简体   繁体   English

Python pandas 读取文件错误:ParserError:标记数据时出错。 C错误:

[英]Python pandas reading file error: ParserError: Error tokenizing data. C error:

I'd like to read this file: https://ufile.io/7orq1ch4我想阅读这个文件: https : //ufile.io/7orq1ch4

result = pd.read_table('Testdata2.txt' , decimal = ',')
print(result)

but the following error occurs但出现以下错误

File "pandas/_libs/parsers.pyx", line 2132, in pandas._libs.parsers.raise_parser_error文件“pandas/_libs/parsers.pyx”,第 2132 行,在 pandas._libs.parsers.raise_parser_error

ParserError: Error tokenizing data. ParserError:标记数据时出错。 C error: Expected 1 fields in line 4, saw 11 C 错误:第 4 行中应有 1 个字段,看到 11

尝试pd.read_csv('Testdata2.txt', decimal = ',')而不是pd.read_table

If you get rid of the first 3 lines of testdata2.txt and try to load with如果你去掉testdata2.txt的前 3 行并尝试加载

df = pd.read_table('testdata2.txt', sep='\t', decimal=',')
print(df)

You get:你得到:

   Unnamed: 0 Unnamed: 1    Name 1  ...     Name 7     Name 8  Unnamed: 10
0     Value 1     Nr : 1  8681.874  ...  10642.554  10052.674          NaN
1      [Unit]     Nr : 2  8845.703  ...   5071.242   8091.932          NaN
2         NaN     Nr : 3  8776.430  ...   5574.648   6134.294          NaN
3         NaN     Nr : 4  8908.256  ...   5540.018   7125.733          NaN
4         NaN     Nr : 5  8569.452  ...   4841.109   7034.558          NaN
5         NaN     Nr : 6  8903.974  ...   4944.648   6724.618          NaN
6         NaN     Nr : 7  8678.188  ...   4838.960   6583.222          NaN
7         NaN     Nr : 8  8721.757  ...   5345.413   5829.537          NaN
8         NaN     Nr : 9  8792.308  ...   5177.859   6244.115          NaN
9         NaN    Nr : 10  8604.521  ...   4683.798   6081.107          NaN
10        NaN    Nr : 11  8945.809  ...   5888.516   6463.932          NaN
11        NaN    Nr : 12  8668.207  ...        NaN        NaN          NaN
12        NaN    Nr : 13  8865.165  ...        NaN        NaN          NaN
13        NaN    Nr : 14  8973.844  ...        NaN        NaN          NaN
14        NaN    Nr : 15  8645.630  ...        NaN        NaN          NaN
15        NaN    Nr : 16  8915.668  ...        NaN        NaN          NaN
16        NaN    Nr : 17  8931.855  ...        NaN        NaN          NaN
17        NaN    Nr : 18  9136.108  ...        NaN        NaN          NaN
18        NaN    Nr : 19  8605.307  ...        NaN        NaN          NaN
19        NaN    Nr : 20  8886.002  ...        NaN        NaN          NaN
20        NaN    Nr : 21  8729.902  ...        NaN        NaN          NaN
21        NaN    Nr : 22  8781.786  ...        NaN        NaN          NaN
22        NaN    Nr : 23  8760.748  ...        NaN        NaN          NaN
23        NaN    Nr : 24  9281.921  ...        NaN        NaN          NaN
24        NaN    Nr : 25  8842.649  ...        NaN        NaN          NaN
25        NaN       Mean  8818.123  ...   5686.251   6942.339          NaN
26    Value 2     Nr : 1   804.036  ...    985.616    930.987          NaN
27     [Unit]     Nr : 2   819.208  ...    469.652    749.401          NaN
28        NaN     Nr : 3   812.793  ...    516.273    568.102          NaN
29        NaN     Nr : 4   825.001  ...    513.066    659.921          NaN
30        NaN     Nr : 5   793.625  ...    448.339    651.477          NaN
31        NaN     Nr : 6   824.605  ...    457.928    622.773          NaN
[truncated]

Depending on what you are doing, I suggest you to fill the NaN values using:根据您在做什么,我建议您使用以下方法填充 NaN 值:

df.fillna(0, inplace=True)

Bye!再见!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ParserError:标记数据时出错。 C 错误:第 4 行预期有 7 个字段,在读取 csv 文件 pandas 时看到 10 个错误 - ParserError: Error tokenizing data. C error: Expected 7 fields in line 4, saw 10 error in reading csv file pandas Python 捕获异常“pandas.errors.ParserError:错误标记数据。C 错误” - Python catch exception "pandas.errors.ParserError: Error tokenizing data. C error" Python:pandas.errors.ParserError:错误标记数据。 C 错误:预计第 21 行中的 1 个字段,看到 2 - Python: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 21, saw 2 pandas “pandas.errors.ParserError:错误标记数据。 C 错误:IO 回调中出现未知错误” - pandas “pandas.errors.ParserError: Error tokenizing data. C error: Unknown error in IO callback” ParserError:标记数据时出错。 C错误:预期 - ParserError: Error tokenizing data. C error: Expected Pandas ParserError:标记数据时出错。 C 错误:字符串中的 EOF - Pandas ParserError: Error tokenizing data. C error: EOF inside string Python:ParserError:错误标记数据。 C 错误:字符串中的 EOF 从第 305768 行开始 - Python : ParserError: Error tokenizing data. C error: EOF inside string starting at row 305768 Pandas,ParserError:错误标记数据 - Pandas, ParserError: Error tokenizing data Python Pandas:标记数据时出错。 C 错误:读取 1GB CSV 文件时字符串中的 EOF 开始 - Python Pandas: Error tokenizing data. C error: EOF inside string starting when reading 1GB CSV file 标记数据时出错。 C 错误:pandas python 内存不足,大文件 csv - Error tokenizing data. C error: out of memory pandas python, large file csv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM