ParserError: Error tokenizing data. C error: Expected 1 fields in line 122, saw 2

ぃ、小莉子 提交于 2020-12-19 05:59:47

数据分析和挖掘实战第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 2

  

修改为:

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')

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!