我有两个数据帧df1
和df2
。 df1
包含列subject_id
和time
和df2
包含列subject_id
和final_time
。我想要做的是每subject_id
在df1
添加一列final_time
从df2
但只有subject_ids
的包含在df1
。我试过df1.merge(df2,how='left')
,但仍然得到subject_id
的df2
这个长度更长,并且包含许多重复的'subject_id`。熊猫合并添加列
的例子就是我在寻找:
df1
subject_id time
0 15 12:00
1 20 12:05
2 21 12:10
3 25 12:00
df2
subject_id final_time
0 15 12:30
1 15 12:30
2 15 12:30
3 20 12:45
4 20 12:45
5 21 12:50
6 25 1:00
7 25 1:00
8 25 1:00
什么我找
subject_id time final_time
0 15 12:00 12:30
1 20 12:05 12:45
2 21 12:10 12:50
3 25 12:00 1:00
可以显示示例代码,以及预期的输出是什么? – SeeDerekEngineer