I have two data frames that look like
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 combine two data frames and simply assign the comment column in the second data frame as the first based on the abb column as follows:
df1.merge(df2, how='inner', on='abb')
as a result of:
name ID abb comment 0 foo 251803 I fine 1 bar 376811 R repeat 2 baz 174254 Q other
This works well for unique single-letter identifiers in abb . However, he obviously fails for more than one character.
I tried using list in the abb column in the first data frame, but this leads to a KeyError .
I would like to do the following.
1) Divide lines containing more than one character in this column into several lines
2) Merging data frames
3) Optional: concatenate lines again
source share