Edamame Edamame - 3 months ago 11
Python Question

python: pandas join two data frames

I am trying to join two data frames:

df1:

team | color
---------------
A | blue
B | yellow
C | red


df2:

team | members
---------------
A | 5
B | 10
C | 8


I did:

result = pd.concat([df1, df2], axis=1, join='outer')

team | color | team | members
-----------------------------
A | blue | A | 5
B | yellow | B | 10
C | red | C | 8





The column
team
is duplicated. How do I join the data frame to get the following result:

team | color | members
-----------------------------
A | blue | 5
B | yellow | 10
C | red | 8


Thanks a lot!

Answer

Here:

pd.merge(df1, df2, how='outer', on='team')
Comments