我正在尝试从URL打开一个zip文件,并将其直接加载到熊猫中。一切顺利,直到最终读入pandas步骤,在该步骤中引发错误:
ParserError: Error tokenizing data. C error: Expected 1 fields in line 5, saw 2
当我将完全相同的文件写入磁盘,然后写入熊猫时,它工作正常。有人有主意吗?
#requests object (zipfile url)
resp = urlopen(url)
#load zipfile object in BytesIO
zipfile = ZipFile(BytesIO(resp.read()))
#open specific file in zipfile
sourcedata = zipfile.open(zipfile.namelist()[0])
#read file in pandas, throws error
outputdata = pd.read_csv(sourcedata,skiprows=0)
#this goes fine, reading the sourcedata object doesn't
outputdata = pd.read_csv('file.csv',skiprows=0)