{'df1': name color type
Apple Yellow Fruit,
'df2': name color type
Banana Red Fruit,
'df3': name color type
Chocolate brown Sweet
......}
我想将它们合并为一个像这样:
name color type
Apple Red Fruit
Banana Yellow Fruit
Chocolate brown Sweet
我可以手动完成,如下所示:
merge1=pd.merge('df1','df2')
merge2=pd.merge('merge1','df3')
...
但有没有办法自动压缩字典并合并?
任何帮助表示赞赏.
解决方法:
你可以直接传递dict并访问values属性到concat
:
In [233]:
d
Out[233]:
{'df1': name color type
0 Apple Yellow Fruit, 'df2': name color type
0 Banana Red Fruit, 'df3': name color type
0 Chocolate brown Sweet}
In [234]:
pd.concat(d.values(), ignore_index=True)
Out[234]:
name color type
0 Banana Red Fruit
1 Apple Yellow Fruit
2 Chocolate brown Sweet
这假设您只是想要连接所有dfs,如果要合并,那么您需要解释合并条件是什么
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。