I have two dataframes that share (some) ids (specified in index.name) and I want to intersect them.
So given:
dfA.index.name = 'id'
dfB.index.name = 'id'
and dfA being like:
count
id
1 15
3 16
8 1
and dfB being like:
owns
id
1 True
3 False
12 False
I want to obtain dfC being like:
count owns
id
1 15 True
3 16 False
I tried
s1 = pd.merge(dfA, dfB, how='inner', on=['id'])
without success
I'd use join in this case:
dfC = dfA.join(dfB, how='inner')
You should merge on indexes, not on columns:
s1 = pd.merge(dfA, dfB, left_index=True, right_index=True)
Assigning a name to an index does not make it a column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With