我有一个大的数据框,我试图在concat
之后分割它。 我用TypeError:第一个参数必须是pandas对象的迭代,你传递了一个类型为“DataFrame”的对象
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"
我该如何解决呢?
错误很明显,但即使您确实传递了一个数据框列表,您将覆盖循环中的ID列:'对于df2中的块: chunk ['ID'] = chunk.ID.map(rep.set_index ('member_id')['panel_mm_id'])'这里你的意图是什么?你想创建一些新的DF?你应该做的是将每个块添加到某个列表中,然后调用'concat'对其进行调用 – EdChum
@EdChum我试图从'chunk ['ID]'中替换其他df中的值。接下来我应该使用'chunk = chunk.dropna()',然后我应该连接只在列表中需要的块 –