0

I have two tables which have 2 columns with same values but are shuffled. Table1:

Col1   Col2
  A       3
  B       2
  C       1
  A       4
  E       7

and a second table which looks like this:

Col1   Col2   Col3
  A      1     3.1
  A      2     2.2
  A      3     2.8
  A      4     8
  B      1     4.3
  B      2     6.6  and so on

So what I want to do is associate all the Col3 values from 2nd table into Table1 and get a new table like this:

Col1   Col2   Col3
  A       3    2.8
  B       2    6.6
  C       1     ..

How do I do this in python?

Sahil
  • 439
  • 2
  • 6
  • 17
  • Do you try `df = df1.merge(df2, how='left', on=['Col1','Col2'])` ? It seems dupe. – jezrael Feb 24 '18 at 12:09
  • To merge two dataframes on two primary keys (variables) you should use the `pd.merge()` method and specify the two variables as the primary keys, like so: `df1.merge(df2, how='left', on=['Col1','Col2'])` – Keith Dowd Feb 24 '18 at 17:06

0 Answers0