pythonpandascsv

How to solve python error "does not exist" when using pd.read_csv() and absolute path?


I've been trying to import a csv file from my Desktop folder (Mac) but getting error message "File does not exist." Problem is I'm copying the full path name and can confirm the file in fact exists. Anyone able to point out what step I'm missing? (using Google colab notebook)

CODE:
pd.read_csv(filepath_or_buffer='/Users/ekselan/Desktop/NBA DFS/FantasyLabs_NBAProjections_3_7_2020.csv')

ERROR:

<ipython-input-7-7fbf5886b6a2> in <module>()
----> 1 pd.read_csv(filepath_or_buffer='/Users/ekselan/Desktop/NBA DFS/FantasyLabs_NBAProjections_3_7_2020.csv')

4 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   1915         kwds["usecols"] = self.usecols
   1916 
-> 1917         self._reader = parsers.TextReader(src, **kwds)
   1918         self.unnamed_cols = self._reader.unnamed_cols
   1919 

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] File b'/Users/ekselan/Desktop/NBA DFS/FantasyLabs_NBAProjections_3_7_2020.csv' does not exist

I also get the same error when using pd.read_csv(r'/Users/ekselan/Desktop/NBA DFS/FantasyLabs_NBAProjections_3_7_2020.csv')

Screenshot of the Google colab notebook


Solution

  • Just upload your that file.

    from google.colab import files
    uploaded = files.upload()
    

    import pandas as pd
    import io
    
    df = pd.read_csv(io.StringIO(uploaded['FantasyLabs_NBAProjections_3_7_2020.csv'].decode('utf-8')))
    df
    

    Note: Since you are not uploading it to your gdrive. Once you will restart the kernel this file will get removed as this is stored temporary. Once the session is lost you will lose it.