使用pandas.read_csv函数无法读取ASCII格式的CSV文件

时间:2019-08-30 06:20:39

标签: pandas csv ascii

我正在尝试读取ASCII格式的CSV文件。我从读取文件中得到的错误是:

Reading file.csv ... Traceback (most recent call last):
  File "viewdate.py", line 164, in <module>
    konv_og_gjenopp = lib_filinnlesing.les_csv(filnavn, renamedict={'AGR_LINE_NO':'agr_line_no'})
  File "/mnt/c/Users/keweik/Desktop/githubfolder/Oystein/lib_filinnlesing.py", line 40, in les_csv
    usecols=kolonner, parse_dates=datokolonner, date_parser=dateparse, dtype=dtype, error_bad_lines=False)
  File "/home/keweiw/.local/lib/python3.6/site-packages/pandas/io/parsers.py", line 685, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/home/keweiw/.local/lib/python3.6/site-packages/pandas/io/parsers.py", line 463, in _read
    data = parser.read(nrows)
  File "/home/keweiw/.local/lib/python3.6/site-packages/pandas/io/parsers.py", line 1154, in read
    ret = self._engine.read(nrows)
  File "/home/keweiw/.local/lib/python3.6/site-packages/pandas/io/parsers.py", line 2059, in read
    data = self._reader.read(nrows)
  File "pandas/_libs/parsers.pyx", line 881, in pandas._libs.parsers.TextReader.read
  File "pandas/_libs/parsers.pyx", line 896, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas/_libs/parsers.pyx", line 950, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 937, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas/_libs/parsers.pyx", line 2124, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 225692: invalid continuation byte

编辑:尝试设置编码,但没有任何效果。

0 个答案:

没有答案