pandas.errors.ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malf...

读取CSV文件的时候报错:
df = pd.read_csv(path + 'data.csv',
sep='\t',
encoding='utf-8')
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\gpu\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 3, in
encoding='utf-8')
File "d:\Documents\zhangmeng4\Application Data\Python\Python37\site-packages\pandas\io\parsers.py", line 605, in read_csv
return _read(filepath_or_buffer, kwds)
File "d:\Documents\zhangmeng4\Application Data\Python\Python37\site-packages\pandas\io\parsers.py", line 463, in _read
return parser.read(nrows)
File "d:\Documents\zhangmeng4\Application Data\Python\Python37\site-packages\pandas\io\parsers.py", line 1052, in read
index, columns, col_dict = self._engine.read(nrows)
File "d:\Documents\zhangmeng4\Application Data\Python\Python37\site-packages\pandas\io\parsers.py", line 2056, in read
data = self._reader.read(nrows)
File "pandas_libs\parsers.pyx", line 756, in pandas._libs.parsers.TextReader.read
File "pandas_libs\parsers.pyx", line 771, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas_libs\parsers.pyx", line 827, in pandas._libs.parsers.TextReader._read_rows
File "pandas_libs\parsers.pyx", line 814, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas_libs\parsers.pyx", line 1951, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

解决办法:在pd.read_csv的参数里面增加:engine='python',完美解决
df = pd.read_csv(path + 'data.csv',
sep='\t',
encoding='utf-8',
engine='python')

后来发现字段有些错乱,最后解决方法如下:
df = pd.read_csv(path + 'data.csv',
sep='\t',
encoding='utf-8',
lineterminator='\n')

你可能感兴趣的:(pandas.errors.ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malf...)