1
df_merged = df1.merge(df2, left_on = ['a', 'b', 'c'], right_on = ['d', 'e', 'f'], how = 'inner')

Let's say I want all df2 columns plus some specific df1 columns. The code gives (df1 & df2) columns. If I'm being selective on df1 columns by typing df1['a','b','c','g','h','i'].merge, I will get df2 columns plus ['a','b','c','g','h','i'] from df1 where I only want ['g', 'h', 'i'].

Thanks in advance for your help.

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
Triphon
  • 11
  • 2
  • 2
    check this post out : https://stackoverflow.com/questions/53645882/pandas-merging-101 – Umar.H Feb 06 '19 at 15:55
  • 2
    you can just select the slice of df1 which includes the left_on keys and the interested columns and merge with df2 – anky Feb 06 '19 at 15:59
  • You should be using `pd.concat` instead. – a_guest Feb 06 '19 at 16:30
  • I'm very sorry and thank you for your replies but this is not answered. The panda merging 101 doc is a good one but removing duplicate keys by set_index doesn't work when you want specifying columns and the ['key', 'column'] choice for one specific columns doesn't work with multiples and different keys (same for map ). Am I missing something ? If yes, could someone be more explicit ? thanks – Triphon Feb 07 '19 at 08:43

0 Answers0