0
$\begingroup$

I'm in Machine Learning A-Z lecture 19 where we access our first dataset. I've connected to the Google Colab folder in my gmail account, but when I try to access the the file I get the below error message; any ideas? I've been trying for a couple hours and could use some help:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-8cbde3511752> in <module>()
----> 1 dataset = pd.read_csv('Data.csv')
      2 X = dataset.iloc[:, :-1].values
      3 y = dataset.iloc[:, -1].values

4 frames
/usr/local/lib/python3.7/dist-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   2008         kwds["usecols"] = self.usecols
   2009 
-> 2010         self._reader = parsers.TextReader(src, **kwds)
   2011         self.unnamed_cols = self._reader.unnamed_cols
   2012 

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: [Errno 2] No such file or directory: 'Data.csv'
$\endgroup$
1
  • 1
    $\begingroup$ Your file is not located on the google colab drive directly but in one of the subfolders. Look at the file tree on the left to see in which folder the file is located and use that filepath (probably something like content/drive/...) in pd.read_csv. $\endgroup$
    – Oxbowerce
    Commented Aug 6, 2021 at 17:22

1 Answer 1

1
$\begingroup$

These are the steps to import your file into collab:-

1.) Upload/save your dataset to google drive.

2.) Start by connecting gdrive into the google colab. Run these lines in your collab

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

3.) You will be given a link and asked to enter an authorization code. Go to the link, copy it and paste it.

4.) Now your GDrive is mounted! Now you will see your Google Drive files in the left pane (file explorer). Right click on the file that you need to import and select çopy path. Then import as usual in pandas, using this copied path.

import pandas as pd
df=pd.read_csv('gdrive/My Drive/data.csv')

Voila you have imported your dataset into collab!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.