I have two dataframes df1 and df2 and I want to merge them.
Dataframe df1 is as follows:
IDs Value1 Value2
AB 1 3
AB 1 1
AB 2 4
BC 2 2
BC 5 0
BG 1 1
RF 2 2
and dataframe df2 is as follows:
IDs Issue
AB AA
AB AAA
AB BA
BC CC
BC CA
BG A
RF D
and the desired output is df3:
IDs Value1 Value2 Issue
AB 1 3 AA
AB 1 1 AAA
AB 2 4 BA
BC 2 2 CC
BC 5 0 CA
BG 1 1 A
RF 2 2 D
Currently, the following:
df3 = pd.merge(df1,df2,left_on='IDs',right_on='IDs',how='inner')
df3 = pd.merge(df1,df2,left_on='IDs',right_on='IDs',how='left')
df3 = pd.merge(df1,df2,left_on='IDs',right_on='IDs',how='outer')
do not work, since they produce a result similar to the following:
IDs Value1 Value2 Issue
AB 1 3 AA
AB 1 1 AA
AB 2 4 AA
BC 2 2 CC
BC 5 0 CC
BG 1 1 A
RF 2 2 D
meaning that they duplicate the first value of the Issue field from df2.