使用加入在大熊猫中加入2个数据框
我有两个数据帧DF1和DF2
DF1
id name
ada1 mike
ad23 tom
cev2 tim
DF2
id month. sales
ada1. 1/11. 23
ada1. 4/11. 34
ad23. 3/12. 34
cev2. 4/11. 32
我需要:
id month. sales name
ada1. 1/11. 23. mike
ada1. 4/11. 34. mike
ad23. 3/12. 34. tom
cev2. 4/11. 32. tim
我在左联接或右JOIN之间被击中,我应该使用什么。
I have two data frames df1 and df2
df1
id name
ada1 mike
ad23 tom
cev2 tim
df2
id month. sales
ada1. 1/11. 23
ada1. 4/11. 34
ad23. 3/12. 34
cev2. 4/11. 32
I need :
id month. sales name
ada1. 1/11. 23. mike
ada1. 4/11. 34. mike
ad23. 3/12. 34. tom
cev2. 4/11. 32. tim
I am struck between left join or right join, what should i use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
pd.merge
:Use
pd.merge
:使用映射,因为您将在一列上加入\合并并返回一列。
地图将胜过加入\合并。
Use map, since you are joining\merging on one column and returning one column.
Map will outperform join\merge.
提供两种可以根据问题集提供帮助的方法
Providing two methods that can help based on problem set