本文介绍了Python 3 Pandas错误:pandas.parser.CParserError:错误标记数据。 C错误:第5行中的11个字段,第13个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我检查了这个答案,因为我有类似的问题。
但是,由于某种原因,我的所有行都被跳过。
我的代码很简单:
import pandas as pd
fname =data.csv
input_data = pd.read_csv(fname)
我得到的错误是:
文件preprocessing.py,第8行,在< 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,第465行,在parser_f
return _read(filepath_or_buffer,kwds)
文件/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers.py,行251,在_read
中返回parser.read()
文件/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/parsers。 py,行710,在读
ret = self._engine.read(nrows)
文件/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages /pandas/io/parsers.py,行1154,在读取
data = self._reader.read(nrows)
文件pandas / parser.pyx,行754,在pandas.parser。 TextReader.read(pandas / parser.c:7391)
文件pandas / parser.pyx,第776行,在pandas.parser.TextReader._read_low_memory(pandas / parser.c:7631)
文件pandas / parser.py:8253)
在pandas.parser.TextReader中的文件pandas / parser.pyx,第816行,pandas / parser.pyx,第829行,pandas.parser.TextReader._read_rows ._tokenize_rows(pandas / parser.c:8127)
文件pandas / parser.pyx,第1728行,位于pandas.parser.raise_parser_error(pandas / parser.c:20357)
pandas.parser。 CParserError:错误标记数据。 C错误:第5行中的11个字段,共13个
解决方案
解决方案是使用pandas内置的分隔符嗅探。
input_data = pd.read_csv(fname,sep =
I checked out this answer as I am having a similar problem.
Python Pandas Error tokenizing data
However, for some reason ALL of my rows are being skipped.
My code is simple:
import pandas as pd
fname = "data.csv"
input_data = pd.read_csv(fname)
and the error I get is:
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
解决方案
Solution is to use pandas built-in delimiter "sniffing".
input_data = pd.read_csv(fname, sep=None)
这篇关于Python 3 Pandas错误:pandas.parser.CParserError:错误标记数据。 C错误:第5行中的11个字段,第13个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!