使用read_csv方法读取数据文件报错

读取文件并打印

import pandas as pd
csv_data = pd.read_csv('train.csv',names=['review','label'])
print (csv_data)

报错
Traceback (most recent call last):
File “G:/data/readdata.py”, line 2, in
csv_data = pd.read_csv(‘train.csv’,names=[‘review’,‘label’])
File “C:\Users\Administrator\PycharmProjects\tensorflow\venv\lib\site-packages\pandas\io\parsers.py”, line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File “C:\Users\Administrator\PycharmProjects\tensorflow\venv\lib\site-packages\pandas\io\parsers.py”, line 435, in _read
data = parser.read(nrows)
File “C:\Users\Administrator\PycharmProjects\tensorflow\venv\lib\site-packages\pandas\io\parsers.py”, line 1139, in read
ret = self._engine.read(nrows)
File “C:\Users\Administrator\PycharmProjects\tensorflow\venv\lib\site-packages\pandas\io\parsers.py”, line 1995, in read
data = self._reader.read(nrows)
File “pandas_libs\parsers.pyx”, line 899, in pandas._libs.parsers.TextReader.read
File “pandas_libs\parsers.pyx”, line 914, in pandas._libs.parsers.TextReader._read_low_memory
File “pandas_libs\parsers.pyx”, line 968, in pandas._libs.parsers.TextReader._read_rows
File “pandas_libs\parsers.pyx”, line 955, in pandas._libs.parsers.TextReader._tokenize_rows
File “pandas_libs\parsers.pyx”, line 2172, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Buffer overflow caught - possible malformed input file.

修改

import pandas as pd
csv_data = pd.read_csv('train.csv',names=['review','label'],lineterminator='\n')
print (csv_data)

pandas用作行终止符的数据中有一些回车符
使用read_csv方法读取数据文件报错_第1张图片

你可能感兴趣的:(python)