【发布时间】:2019-03-02 00:57:51
【问题描述】:
我目前有两个数据框:
df1:
col1 col2 col3 col4
0 Apple store1 1 3
1 Tree store2 1 3
2 Banana store3 2 4
3 Card store4 2 4 ...
df2:
col1 col2 col3 col4 col5 col6
0 Apple store1 1 3 123 50
1 Tree store2 1 3 451 32
2 Mango store2 2 4 313 15
3 Guava store5 2 4 113 9
如果前 4 列中的值相同,我想要将 df1 和 df2 合并在一起,但我想将 col5 和 col6 的值附加到合并的数据框中。所以理想的输出是:
merged_df:
col1 col2 col3 col4 col5 col6
0 Apple store1 1 3 123 50
1 Tree store2 1 3 451 32 ...
当我尝试合并时,我在合并的数据帧上的 col5 和 col6 上返回了 NaN 值。请问有什么想法吗?
谢谢
【问题讨论】:
标签: python pandas dataframe merge