python 使用read_csv讀取 CSV 文件時報錯


讀取csv文件時報錯 

df = pd.read_csv('c:/Users/NUC/Desktop/成績.csv' )

Traceback (most recent call last):
  File "D:/學習/helloworld/helloworld.py", line 268, in <module>
    df = pd.read_csv('c:/Users/NUC/Desktop/成績.csv' )
  File "D:\學習\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "D:\學習\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 440, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
  File "D:\學習\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 787, in __init__
    self._make_engine(self.engine)
  File "D:\學習\Python\Python-3.6.5\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "D:\學習\Python\Python-3.6.5\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 697, in pandas._libs.parsers.TextReader._setup_parser_source
OSError: Initializing from file failed

解決:

df = pd.read_csv('c:/Users/NUC/Desktop/成績.csv', engine='python' )
加上 engine = 'python'
engine的參數有三個 'c','python','python_fwf'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM