0
votes

I am using Google Colab for reading my jupyter notebooks from Google Drive. I opened an exisiting notebook and while reading the csv file, I got an error. Both my notebook and csv file are in the same location - please see screenshot. I am working with the Practice_1_of_5,ipynb notebook and reading bands.csv file.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data= pd.read_csv('bands.csv', header = none)
data.head()

What could be the issue?

Thanks.Google Drive Image

2
Do include some code here - Cool Cloud
I have just updated the code to read file. - SidStack

2 Answers

0
votes

Did you mount your drive to the colab notebook?

You can access files on your drive only after you mount your drive to the colab notebook.

Once you mount the drive, the file structure will look something similar to this:

content
└───drive
    ├───My Drive
    │   ├───"Contents of your drive here"

In this case your code should look something like this

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data= pd.read_csv('drive/My Drive/Colab Notebooks/bands.csv', header = none)
data.head()
0
votes

You have to use the Google Drive API:

from google.colab import drive
import pandas as pd

# this will ask you to log in and copy an authentication code
drive.mount("/content/drive")

path = "/content/drive/My Drive/bands.csv"

df = pd.read_csv(path)

You can see the path to the file by clicking on the folder that will appear on a bar to the left of the screen.