【发布时间】:2019-12-02 00:52:12
【问题描述】:
我有两个数据框:
>>> df1
[Output]: col1 col2 col3 col4
a abc 10 str1
b abc 20 str2
c def 20 str2
d abc 30 str2
>>> df2
[Output]: col1 col2 col3 col5 col6
d abc 30 str6 47
b abc 20 str5 66
c def 20 str7 53
a abc 10 str5 21
下面是我想要生成的:
>>> df_merged
[Output]: col1 col2 col5
a abc str5
b abc str5
c def str7
d abc str6
我不想生成超过 4 行,这通常是我尝试合并数据帧时发生的情况。感谢您的提示!
【问题讨论】:
-
我不太明白你试图合并什么。只是col1? col1 和 2?在您的示例中,这实际上并不重要。
-
为什么是
merge?我只看到带有子集列的已排序df2?