【Python综合学习】Pandas读取csv文件OSError报错

【Python综合学习】Pandas读取csv文件OSError报错_第1张图片


  File "C:\Users\SJM\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 705, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\SJM\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 445, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "C:\Users\SJM\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 814, in __init__
    self._make_engine(self.engine)
  File "C:\Users\SJM\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 1045, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "C:\Users\SJM\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 1684, in __init__
    self._reader = parsers.TextReader(src, **kwds)
  File "pandas\_libs\parsers.pyx", line 391, in pandas._libs.parsers.TextReader.__cinit__
  File "pandas\_libs\parsers.pyx", line 712, in pandas._libs.parsers.TextReader._setup_parser_source
OSError: Initializing from file failed


分析:

Error在于_setup_parser_source ,说明文件压根没有读到,导致该原因一般为文件路径出现问题,检查是否有中文,中文有时会导致该问题。


解决方案:

修改文件路径名为全英文包括文件名。

你可能感兴趣的:(python,Pandas,csv,OSError)