gpt4 book ai didi

csv - Python 3 Pandas 错误 : pandas. parser.CParserError : Error tokenizing data. C 错误 : Expected 11 fields in line 5, 看到 13

转载 作者:行者123 更新时间:2023-12-04 21:52:03 25 4
gpt4 key购买 nike

我检查了这个答案,因为我遇到了类似的问题。

Python Pandas Error tokenizing data

但是,由于某种原因,我的所有行都被跳过了。

我的代码很简单:

import pandas as pd

fname = "data.csv"
input_data = pd.read_csv(fname)

我得到的错误是:
  File "preprocessing.py", line 8, in <module>
input_data = pd.read_csv(fname) #raw data file ---> pandas.core.frame.DataFrame type
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers.py", line 465, in parser_f
return _read(filepath_or_buffer, kwds)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers.py", line 251, in _read
return parser.read()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers.py", line 710, in read
ret = self._engine.read(nrows)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers.py", line 1154, in read
data = self._reader.read(nrows)
File "pandas/parser.pyx", line 754, in pandas.parser.TextReader.read (pandas/parser.c:7391)
File "pandas/parser.pyx", line 776, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:7631)
File "pandas/parser.pyx", line 829, in pandas.parser.TextReader._read_rows (pandas/parser.c:8253)
File "pandas/parser.pyx", line 816, in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:8127)
File "pandas/parser.pyx", line 1728, in pandas.parser.raise_parser_error (pandas/parser.c:20357)
pandas.parser.CParserError: Error tokenizing data. C error: Expected 11 fields in line 5, saw 13

最佳答案

解决方案是使用 Pandas 内置的分隔符“嗅探”。

input_data = pd.read_csv(fname, sep=None) 

关于csv - Python 3 Pandas 错误 : pandas. parser.CParserError : Error tokenizing data. C 错误 : Expected 11 fields in line 5, 看到 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29754786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com