熊猫:数据框联合

时间:2019-06-15 22:24:24

标签: python pandas

考虑两个数据框,如下所示:

{"captchaResponse":"","display_size":"40","productId":"FU7914_590","product_id":"FU7914","product_variation_sku":"FU7914_590","quantity":1,"size":"40"}

我必须从它们的联合中创建第三个数据框。我需要比较两个数据帧的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']}) 值,如果它们相同,则第三个数据帧除了id_emp之外还将接收列id_empname_dep。预期的输出结果如下:

description

1 个答案:

答案 0 :(得分:1)

您需要的是合并:

df.merge(df2)