成功解决pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 2

问题描述:

Traceback (most recent call last):
  File "C:/Users/Lenovo/Desktop/水泥数据/dataprocess1.py", line 8, in 
    data1 = pd.read_csv("doubledata.xlsx")
  File "D:\Users\Lenovo\miniconda3\lib\site-packages\pandas\io\parsers.py", line 676, in parser_f    return _read(filepath_or_buffer, kwds)
  File "D:\Users\Lenovo\miniconda3\lib\site-packages\pandas\io\parsers.py", line 454, in _read
    data = parser.read(nrows)
  File "D:\Users\Lenovo\miniconda3\lib\site-packages\pandas\io\parsers.py", line 1133, in read
    ret = self._engine.read(nrows)
  File "D:\Users\Lenovo\miniconda3\lib\site-packages\pandas\io\parsers.py", line 2037, in read
    data = self._reader.read(nrows)
  File "pandas\_libs\parsers.pyx", line 860, in pandas._libs.parsers.TextReader.read
  File "pandas\_libs\parsers.pyx", line 875, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas\_libs\parsers.pyx", line 929, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 916, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas\_libs\parsers.pyx", line 2071, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 

报错在:

pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 21

源码位置:

data1 = pd.read_csv("doubledata.xlsx")1

问题是:数据格式出错

解决方案:

  1. 数据后缀转为.csv格式,在windows下打开,并保存关闭一次即可。关闭时,选项选yes

你可能感兴趣的:(python)