2

First time using Google Colab. I have used a Kaggle API and I have the data loaded into Google Colab, but I can't seem to open it via pandas. I right clicked on the file and copied path. I then ran the following code:

import pandas as pd train = pd.read_csv("content/train.csv") test = pd.read_csv('content/test.csv') 

The error code that I am getting:

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

Here is the code for everything I have done leading up to this error:

!pip install kaggle from google.colab import files files.upload() #Uploaded my kaggle.json file !pip install -q kaggle !mkdir -p ~/.kaggle !cp kaggle.json ~/.kaggle/ !kaggle competitions download -c microsoft-malware-prediction #Unzip the files: !7z x train.csv.zip !7z x sample_submission.csv.zip !7z x test.csv.zip #remove the zipped data !rm train.csv.zip !rm sample_submission.csv.zip !rm test.csv.zip import pandas as pd train = pd.read_csv("content/train.csv") test = pd.read_csv('content/test.csv') print('read') 

Any help would be great!

2
  • Are you missing a leading / in your path? i.e., /content/... rather than content/.... Commented Jan 29, 2019 at 16:38
  • Hello. Yes, I have included that. I am now suspecting that it is a permission issue with the source in which I am getting the data. Thank you for your help though. Commented Jan 29, 2019 at 20:05

4 Answers 4

3

It happened to me too but I was able to resolve with reading the .csv file with a new syntax:

  • Enter this in a code block above (1st or second)

!pip install -U -q PyDrive

from pydrive.auth import GoogleAuth

from pydrive.drive import GoogleDrive

from google.colab import auth from oauth2client.client import GoogleCredentials

#Authenticate and create the PyDrive client

auth.authenticate_user()

gauth = GoogleAuth()

gauth.credentials = GoogleCredentials.get_application_default()

drive = GoogleDrive(gauth)

Then do this:

link = 'link_to_file_in drive'

fluff, id = link.split('=')

downloaded = drive.CreateFile({'id':id})

downloaded.GetContentFile('name_of_file.csv')

df = pd.read_csv("name_of_file.csv")

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

Comments

0

i encountered with the same issue , what fixed it for me was :

!pip install -U -q PyDrive from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from google.colab import auth from oauth2client.client import GoogleCredentials # 1. Authenticate and create the PyDrive client. auth.authenticate_user() gauth = GoogleAuth() gauth.credentials = GoogleCredentials.get_application_default() drive = GoogleDrive(gauth) # PyDrive reference: # https://gsuitedevs.github.io/PyDrive/docs/build/html/index.html # 2. Create & upload a file text file. uploaded = drive.CreateFile({'title': 'Sample upload.txt'}) uploaded.SetContentString('Sample upload file content') uploaded.Upload() print('Uploaded file with ID {}'.format(uploaded.get('id'))) # 3. Load a file by ID and print its contents. downloaded = drive.CreateFile({'id': uploaded.get('id')}) print('Downloaded content "{}"'.format(downloaded.GetContentString())) from google.colab import drive drive.mount('/content/gdrive', force_remount=True) root_dir = "/content/gdrive/My Drive/" base_dir = root_dir + 'app/' and then each file is refreed as base_dir +file_name 

from https://colab.research.google.com/notebooks/io.ipynb#scrollTo=zU5b6dlRwUQk

Comments

0

Provide the full path for the file irrespective of where you are.

Try below solution, hope it works if you are fetching data from google drive

data = pd.read_csv("/content/drive/My Drive/data/"name_of_the_csv_file") 

Comments

0

In order to open a file in Google Drive:

df=pd.read_csv(" copy and paste the entire path of that file")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.