0

Considering two dataframes like the ones below:

import pandas as pd
df = pd.DataFrame({'id_emp' : [1,2,3,4,5],
                   'name_emp': ['Cristiano', 'Gaúcho', 'Fenômeno','Angelin', 'Souza']})
df2 = pd.DataFrame({'id_emp': [1,2,3,6,7],
                    'name_emp': ['Cristiano', 'Gaúcho', 'Fenômeno', 'Kaká', 'Sérgio'],
                    'Description': ['Forward', 'Middle', 'Forward', 'back', 'winger']})

I have to create a third data frame from the union of them. I need to compare the id_emp values ​​of the two dataframes, if they are the same, the third dataframe will receive the columns name_dep and description, in addition to the id_emp. Expected output result is as follows:

id_emp|name_emp|Description
1     |Cristiano|Forward
2     |Gaúcho   |Middle
3     |Fenômeno |Forward
Costa.Gustavo
  • 849
  • 10
  • 21

1 Answers1

1

All you need is merge:

df.merge(df2)
DYZ
  • 55,249
  • 10
  • 64
  • 93