0

I am doing a simple merge in Pandas. The strange part is that in the column on which I am joining from the right dataframe ends up in the result. So I have twice the same info in different columns and have to drop it.

df1.merge(df2.reset_index().rename(columns={'df_name': df2_name'}),
                            left_on='df_id',
                            right_on='df2_id').drop('df2_id', axis=1).set_index('index')

As you can see I have to drop df2_id at the end because I end up with dataframe containing both df_id and df2_id.

Isn't it normal the column df2_id not to be added to the result of the merge as it is being used as key?

cs95
  • 379,657
  • 97
  • 704
  • 746
MitakaJ9
  • 191
  • 1
  • 2
  • 11

1 Answers1

0

That's the expected result.

If the names are different both columns will be kept.

Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52