Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Csv file not found error in Google colaboratory notebooks

I am trying to load csv file stored in google drive to colab notebooks. When i try to load the file it is showing "File not found". What is the procedure to load files stored in google drive to colab notebooks??

like image 402
avinash Avatar asked Jan 18 '18 14:01

avinash


People also ask

How do I read a CSV file in colab notebook?

Now in the Notebook, at the top-left, there is a File menu and then click on Locate in Drive, and then find your data. Then copy the path of the CSV file in a variable in your notebook, and read the file using read_csv().

How do I import a CSV file into Google Colab?

Click on “Choose Files” then select and upload the file. Wait for the file to be 100% uploaded. You should see the name of the file once Colab has uploaded it. Finally, type in the following code to import it into a dataframe (make sure the filename matches the name of the uploaded file).

How do I connect files to Google Colab?

You can either use the upload option at the top of the file-explorer pane to upload any file(s) from your local file system to Colab in the present working directory. 2. Select the “upload” option.


1 Answers

easiest way I found is mounting google drive in colab:

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

then use '/content/gdrive/My Drive/' as prefix of the file path. suppose you have a text file in data directory of you google drive. Then you can access it with following code:

open('/content/gdrive/My Drive/data/filename.txt').read()
like image 66
priojeet priyom Avatar answered Oct 05 '22 11:10

priojeet priyom