ParserError: Error tokenizing data. C error: Expected 1 fields in line 122, saw 2
Posted LOOK AT ME
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ParserError: Error tokenizing data. C error: Expected 1 fields in line 122, saw 2相关的知识,希望对你有一定的参考价值。
数据分析和挖掘实战第15章的一段读取.txt文件报错
import pandas as pd inputfile = ‘data/meidi_jd.txt‘ outputfile = ‘data/meidi_jd_process_1.txt‘ data = pd.read_csv(inputfile,encoding = ‘utf-8‘,header =None)
File "pandas/_libs/parsers.pyx", line 965, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas/_libs/parsers.pyx", line 2208, in pandas._libs.parsers.raise_parser_error
ParserError: Error tokenizing data. C error: Expected 1 fields in line 122, saw
修改为:
import pandas as pd inputfile = ‘data/meidi_jd.txt‘ outputfile = ‘data/meidi_jd_process_1.txt‘ data = pd.read_csv(inputfile,encoding = ‘utf-8‘,header =None,sep=‘\t‘)
或者:
import pandas as pd inputfile = ‘data/meidi_jd.txt‘ outputfile = ‘data/meidi_jd_process_1.txt‘ data = pd.read_csv(inputfile,encoding = ‘utf-8‘,header =None,delimiter=‘\t‘)
以上是关于ParserError: Error tokenizing data. C error: Expected 1 fields in line 122, saw 2的主要内容,如果未能解决你的问题,请参考以下文章
pandas读取csv文件时报错:ParserError: Error tokenizing data. C error
解决 ERROR: yaml.parser.ParserError: while parsing a block mapping
Docker 问题集锦(21) - 解决 ERROR: yaml.parser.ParserError: while parsing a block mapping