pandas.errors.ParserError: Error tokenizing data. C error: Expected 9 fields in line 3, saw 21
Posted on 2023-06-09 11:52 小翁好 阅读(441) 评论(0) 编辑 收藏 举报用pandas读取csv格式文件时,里面有的行比前面的行 多出好多列,会报下面的错
df = pd.read_csv(file_name_csv,encoding="GBK")
File "pandas\_libs\parsers.pyx", line 905, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 2042, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 9 fields in line 3, saw 21
解决方法是读取指定的列,这样就能保证全部行的列数相同了
df = pd.read_csv(file_name_csv, usecols=['时间','abc','操作类型','号码','Type','service','报竣返回','操作结果','处理说明'],encoding="GBK")