Python:FileNotFoundError:文件b'fleet.csv'不存在

时间:2019-03-02 12:25:48

标签: python pandas csv

当我尝试读取目录中的特定CSV文件时得到FileNotFoundError。 如果我读取了另一个CSV文件,则可以正确读取它,而不会出现任何错误。

我尝试过的

fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
fleet_data=pd.read_csv('Users/Ver/Desktop/Processing/data_fleet.csv',sep=',',index_col=0)
fleet_data=pd.read_csv('Users\Ver\Desktop\Processing\data_fleet.csv',sep=',',index_col=0)
fleet_data=pd.read_csv('data_fleet.csv')

我尝试更改文件名,但是仍然无法正常工作。

错误


fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
Traceback (most recent call last):
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\IPython\core\interactiveshell.py", line 2869, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
    File "<ipython-input-36-9aab06bbbbcc>", line 1, in <module>
        fleet_data=pd.read_csv('data_fleet.csv', sep=',',index_col=0)
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
        return _read(filepath_or_buffer, kwds)
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 440, in _read
        parser = TextFileReader(filepath_or_buffer, **kwds)
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
        self._make_engine(self.engine)
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
        self._engine = CParserWrapper(self.f, **self.options)
    File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\pandas\io\parsers.py", line 1708, in __init__
        self._reader = parsers.TextReader(src, **kwds)
    File "pandas\_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.__cinit__
    File "pandas\_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source
    FileNotFoundError: File b'data_fleet.csv' does not exist

但是

如果我将CSV文件从项目复制到另一个项目文件夹,然后打开Python文件并打开文件(data_fleet.py),我可以毫无问题地读取它。

读取所需文件夹中的文件有什么问题?

2 个答案:

答案 0 :(得分:1)

尝试为其提供绝对路径:

'C:\\Users\\Ver\\Desktop\\Processing\\data_fleet.csv'

答案 1 :(得分:1)

您可以尝试列出目录的内容吗?例如,使用os模块和listdir()函数

>>> import os
>>> contents = os.listdir()
>>> contents

这将使您查看是否有任何奇数字符或某些东西阻止您“查找”