我有兩個數據幀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