pandas.read_csv FileNotFoundError: File b'\xe2\x80\xaa' despite correct path

前端 未结 13 1300
南笙
南笙 2020-12-15 20:14

I\'m trying to load a .csv file using the pd.read_csv() function when I get an error despite the file path being correct and using raw strings.

13条回答
  •  我在风中等你
    2020-12-15 20:57

    $10 says your file path is correct with respect to the location of the .py file, but incorrect with respect to the location from which you call python

    For example, let's say script.py is located in ~/script/, and file.csv is located in ~/. Let's say script.py contains

    import pandas
    df = pandas.read_csv('../file.csv') # correct path from ~/script/ where script.py resides
    

    If from ~/ you run python script/script.py, you will get the FileNotFound error. However, if from ~/script/ you run python script.py, it will work.

提交回复
热议问题