Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't read a file in google colaboratory

Can't read a file in google colaboratory . I have .ipynb file and .csv files in the same directory but when I try to run:

train = pd.read_csv("train.csv") 

I get:

FileNotFoundError: File b'train.csv' does not exist

enter image description here

like image 221
ronseg Avatar asked Feb 24 '18 21:02

ronseg


People also ask

How do I open a file with Google Colaboratory?

To start, log into your Google Account and go to Google Drive. Click on the New button on the left and select Colaboratory if it is installed (if not click on Connect more apps, search for Colaboratory and install it). From there, import Pandas as shown below (Colab has it installed already).

How do I read a CSV file using Google Colab?

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().


1 Answers

I use windows 10 and this worked perfectly for me. Give it try.

Add new folder into your drive. Name it what you want. In my case I named it "Colab Notebook". This is folder where I keep my codes and data file.

First you need to mount your drive. For this run the following one by one

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

After second command it pops link where the authentication key is. Open this link copy the key, paste and press enter.

Now type !ls it has to give something like this drive sample_data

Upload your data file. Either it will be csv or excel file does not matter, but commands will be different for each.

For csv file

train = pd.read_csv('/content/drive/My Drive/Colab Notebook/train.csv')

For excel file it's the same just change pandas command and file extension

like image 81
Okroshiashvili Avatar answered Sep 16 '22 13:09

Okroshiashvili