问题描述
Traceback (most recent call last):
File “D:/python/modelsmy/trainvgg16.py”, line 57, in
df_train = pd.read_csv(train_path)
File “E:\tools\Anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py”, line 688, in read_csv
return _read(filepath_or_buffer, kwds)
File “E:\tools\Anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py”, line 460, in _read
data = parser.read(nrows)
File “E:\tools\Anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py”, line 1198, in read
ret = self._engine.read(nrows)
File “E:\tools\Anaconda\envs\py36\lib\site-packages\pandas\io\parsers.py”, line 2157, in read
data = self._reader.read(nrows)
File “pandas_libs\parsers.pyx”, line 847, in pandas._libs.parsers.TextReader.read
File “pandas_libs\parsers.pyx”, line 862, in pandas._libs.parsers.TextReader._read_low_memory
File “pandas_libs\parsers.pyx”, line 918, in pandas._libs.parsers.TextReader._read_rows
File “pandas_libs\parsers.pyx”, line 905, in pandas._libs.parsers.TextReader._tokenize_rows
File “pandas_libs\parsers.pyx”, line 2042, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 2
报错原因:
偷懒直接修改. xlsx为.csv
解决方案:
import pandas as pd
def to_csv():
xls = pd.read_excel(’./test/results.xlsx’, index_col=0)
xls.to_csv(’./test/label.csv’, encoding=‘utf-8’)
if name == ‘main’:
to_csv()