当两列相同时如何合并两个Pandas DataFrame

时间:2019-11-11 06:55:12

标签: python pandas dataframe

我有以下两个数据框:

  orderItemId     orderId                  orderDate         latestDeliveryDate  
0  BFC0000332253518  2648507110  2019-11-10T21:08:30+01:00  2019-11-11T00:00:00+01:00  
0  BFC0000332123047  2647717360  2019-11-10T15:42:39+01:00  2019-11-11T00:00:00+01:00  
0  BFC0000332291194  2648712140  2019-11-10T22:24:56+01:00  2019-11-11T00:00:00+01:00 

          orderItemId     orderId shipmentId   shipmentReference               shipmentDate
0    BFC0000332253518  2648507110  689508122  081234500926730318  2019-11-11T00:10:06+01:00
1    BFC0000332123047  2647717360  689505054  081234500926572451  2019-11-10T23:55:38+01:00
2    BFC0000332291194  2648712140  689505045  081234500926710549  2019-11-10T23:55:37+01:00

如何将那些与熊猫合并在一起?因为它们有两个相同的列。我可以使用多个on=值吗?

1 个答案:

答案 0 :(得分:0)

是的,您可以使用多个on值。我想从上面的示例中,您想在orderItemIdorderId上合并吗?

只需使用:

final_df = pd.merge(df1, df2, how = 'inner', left_on = ['orderItemId','orderId'], right_on = ['orderItemId','orderId'])