0

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'
3
  • Does SeoulBikeData.csv exists provided location? Commented Feb 6, 2022 at 8:27
  • @AnkitTiwari i think yes , i have downloaded and place it in that location Commented Feb 6, 2022 at 8:30
  • See this stackoverflow.com/questions/47320052/…. Commented Feb 6, 2022 at 9:16

5 Answers 5

2

First you need to load file into local directory of colab enter image description here

here you can click on that folder enter image description here

Click on icon of upload and upload the file you want to read

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

Finally your file will be loaded. enter image description here

But there is limitation whenever you close your notebook on colab you have to done whole process again better way to do this is upload file on drive and mount the drive and load file from drive:

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

After that:

df= pd.read_csv("copy path file here")

Third Way to load file in google colab is:

import io
from google.colab import files
uploaded = files.upload()
df2 = pd.read_csv(io.BytesIO(uploaded['fummy.csv']))

enter image description here

Click on choose file located directory of your file

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

Comments

0

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.

But if you want to use google collab here's where you need to upload

Files >> sample_data >> upload files

Comments

0

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')

after that:

df= pd.read_csv("copy path file here")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.