更新时间:2022-11-17 16:16:47
我相信 DataFrame.merge
在这种情况下会起作用:
I believe that DataFrame.merge
would work in this case:
# use how='outer' to preserve all information from both DataFrames
df1.merge(df2, how='outer', on='customer_id')
DataFrame.join
也可以工作这两个DataFrame的索引都设置为 customer_id
(也更简单):
DataFrame.join
could also work if both DataFrames had their indexes set to customer_id
(it is also simpler):
df1 = df1.set_index('customer_id')
df2 = df2.set_index('customer_id')
df1.join(df2, how='outer')
DataFrame.merge
DataFrame.merge
DataFrame.join