0

For example I do have two DataFrames in Pandas:

First like:

id brand model

1 BMW E30
7 Mercedes W222
5 BMW E46
3 Mercedes W201

Second one like:

id mpg weight

1 15 5000
3 12 4000
7 10 3000
5 20 4500

So I need to put second columns (with mpg and weight) into first dataframe with checking by ID:

id brand model mpg weight
1 BMW E30 15 5000
7 Mercedes W222 10 3000
5 BMW E46 20 4500
3 Mercedes W201 12 4000

How can I do that? Thank you!

John Doe
  • 75
  • 1
  • 10

1 Answers1

1
merged = df1.merge(df2, on=['id'])
Ricky Kim
  • 1,992
  • 1
  • 9
  • 18