I have two data frames which look like this
df1
name ID abb
0 foo 251803 I
1 bar 376811 R
2 baz 174254 Q
3 foofoo 337144 IRQ
4 barbar 306521 IQ
df2
abb comment
0 I fine
1 R repeat
2 Q other
I am trying to use pandas merge
to join the two data frames and simply assign the comment
column in the second data frame to the first based on the abb
column in the following way:
df1.merge(df2, how='inner', on='abb')
resulting in:
name ID abb comment
0 foo 251803 I fine
1 bar 376811 R repeat
2 baz 174254 Q other
This works well for the unique one letter identifiers in abb
. However, it obviously fails for more than one character.
I tried to use list
on the abb
column in first data frame but this results in a KeyError
.
What I would like to do is the following.
1) Seperate the rows containing more than one character in this column into several rows
2) Merge the data frames
3) Optionally: Combine the rows again