【发布时间】:2021-04-22 16:35:14
【问题描述】:
在读取不同文件的 for 循环中生成了数千个一致列的 dfs,我正在尝试将它们合并/连接/附加到单个 df,combined:
combined = pd.DataFrame()
for i in range(1,1000): # demo only
global combined
generate_df() # df is created here
combined = pd.concat([combined, df])
这最初很快,但随着 combined 的增长而变慢,最终变得无法使用。 This answer on how to append rows 解释了如何将行添加到 dict 然后创建 df 是最有效的,但我不知道如何使用 to_dict 做到这一点。
有什么好的方法来解决这个问题?我是不是走错了路?
【问题讨论】:
标签: python pandas dataframe append