• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

TypeError:第参数必须是 pandas 对象的可迭代对象,您传递了类型为"DataFrame"的对象,

用户头像
it1352
帮助1

问题说明

我有一个大数据框,我尝试将其拆分,并在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"

我该如何解决?

正确答案

#1

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

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /reply/detail/tanhcfjjha
系列文章
更多 icon
同类精品
更多 icon
继续加载