-1

I am trying to read simple CSV file in Python. It gives me an FileNotFoundError.I am pretty sure that the file exists on the given location. Interesting thing is that if I use a different CSV file in that same location it reads perfectly fine. I am not sure why it works for one and not for other.

Is it something to do with the CSV file itself? I also tried encoding, but no luck.

    player_stats = pd.read_csv('2017-18_playerBoxScore.csv', parse_dates=['gmDate'])
    FileNotFoundError: File b'2017-18_playerBoxScore.csv' does not exist
    line 440, in _read parser = TextFileReader(filepath_or_buffer, **kwds)

Not sure what is _read parser mean.Any idea why it's behaving like this for different CSV files. I am using pycharm.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Learner
  • 335
  • 3
  • 16
  • try adding the full path .... https://stackoverflow.com/questions/38336501/error-while-reading-a-csv-file-in-python-using-pandas – GiovaniSalazar Dec 15 '19 at 03:59

2 Answers2

0

I would say check the current directory for that file. Maybe try running ls 2017-18_playerBoxScore.csv in bash or powershell?

Check your spelling and capitalization (which will only matter for a case insensitive filesystem)

Not much else I can think of, without more information.

jgeigerm
  • 140
  • 5
0

Since the exact same source-code worked impeccably for other files at the same location, this is what we know:

  • you have the necessary privileges for the folder where your file can be found
  • your source-code works if a correct path is passed
  • for some reason the path you pass is incorrect

This is what we don't know:

  • whether you have the necessary privileges for that file
  • whether there is some inaccuracy in the name of the file (maybe even an invisible whitespace)
  • whether the file is corrupted

You will need to do a Save As for the file and let's save it as myexperiment.csv. If you can open myexperiment.csv, then the problem is an inaccuracy in the name of the file you intend to open. If it cannot open the file, then the issue is related to the file itself.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • From my trail and error experience what i have noticed is if i run the file first and then execute the selected code it works in pycharm. When i run the file it displays the location of a file runfile('C:/Users/Documents/Python/Data_viz/Bokeh/NBA.py', wdir='C:/Users/Documents/Python/Data_viz/Bokeh/nba-enhanced-stats') .May be i have to run the file first and execute the code. I am not sure though – Learner Dec 15 '19 at 13:29