Reputation: 33
a = pd.DataFrame({"a": [1,2], "b": [1,1]})
b = pd.DataFrame({"c": [3,4], "b": [1,1]})
c = a.merge(b, on=['b'], how='inner')
we will get c having 4 lines. But how can we get c like {'a':[1,2], 'c':[3,4], 'b':[1,1]} by using merge() function?
Upvotes: 3
Views: 134
Reputation: 1039
This could work. Pandas merge is not that good when you implement it.
c = pd.concat([a, b], axis=1, join='inner')
c = c.loc[:,~c.columns.duplicated()]
print(c)
returns this:
a b c
0 1 1 3
1 2 1 4
Upvotes: 1