TypeError:第一个参数必须是 pandas 对象的可迭代对象,您传递了一个类型为"DataFrame"的对象, [英] TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame"

查看:123
本文介绍了TypeError:第一个参数必须是 pandas 对象的可迭代对象,您传递了一个类型为"DataFrame"的对象,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大数据框,我尝试将其拆分,并在concat之后. 我用

I have a big dataframe and I try to split that and after concat that. I use

df2 = pd.read_csv('et_users.csv', header=None, names=names2, chunksize=100000)
for chunk in df2:
    chunk['ID'] = chunk.ID.map(rep.set_index('member_id')['panel_mm_id'])

df2 = pd.concat(chunk, ignore_index=True)

但是它返回一个错误

TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame"

我该如何解决?

推荐答案

IIUC,您需要以下内容:

IIUC you want the following:

df2 = pd.read_csv('et_users.csv', header=None, names=names2, chunksize=100000)
chunks=[]
for chunk in df2:
    chunk['ID'] = chunk.ID.map(rep.set_index('member_id')['panel_mm_id'])
    chunks.append(chunk)

df2 = pd.concat(chunks, ignore_index=True)

您需要将每个块添加到列表中,然后使用concat将它们全部连接起来,我也认为ignore_index可能不是必需的,但我可能是错的

You need to append each chunk to a list and then use concat to concatenate them all, also I think the ignore_index may not be necessary but I may be wrong

这篇关于TypeError:第一个参数必须是 pandas 对象的可迭代对象,您传递了一个类型为"DataFrame"的对象,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆