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'
Ankit Tiwari
  • 4,438
  • 4
  • 14
  • 41
New
  • 49
  • 1
  • 8

5 Answers5

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

M. Twarog
  • 2,418
  • 3
  • 21
  • 39
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
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.

EvilReboot
  • 152
  • 10
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
Michael Halim
  • 262
  • 2
  • 20
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")