简体   繁体   中英

(Python)Unable to import excel file using colab

i have tried to import an excel csv file from my local disk but failed

import pandas as pd
df=pd.read_csv(r'C:/Users/Username/Desktop/da/SeoulBikeData.csv',encoding="gbk")
print("df")

error:

FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Username/Desktop/da/SeoulBikeData.csv'

You cannot import local directory excel files directly in Google collab. You have to upload the excel file in the Collab directory and then you can import it.

"

Try uploading files on drive first. Then read. Go to file. Copy path. Try following code.

from google.colab import files
Upload= files.upload
Df= pd.read_csv("file_path_file_name")
df.head

In Google Collab you have to upload it in sample_data folder. But the file will lost after you close it. Other alternatives are jupyter notebook where you can do everything in google collab but offline.

Files >> sample_data >> upload files

Try uploading files on drive first. Then read. Go to file. Copy path. Try following code according to mu method in then below

from google.colab import drive
drive.mount('/content/drive')

First you need to load file into local directory of colab在此处输入图像描述<\/a>

import pandas as pd
df=pd.read_csv(r'fummy.csv',encoding="gbk")
df

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM