匹配pandas中多个数据帧的列

时间:2016-10-26 21:21:23

标签: python pandas dataframe

我有2个数据框,其中包含['名称']和['地址']列。我想让pandas打印第二个数据帧中的行,如果它与第一个数据帧中的名称和地址匹配。

1 个答案:

答案 0 :(得分:1)

考虑d1d2

d1 = pd.DataFrame(dict(Names=list('ABCDEFG'),
                       Addressess=[1, 2, 3, 4, 5, 6, 7]))
d1

enter image description here

d2 = pd.DataFrame(dict(Names=list('FGHIJ'),
                       Addressess=[6, 7, 8, 9, 10]))
d2

enter image description here

然后使用合并

d2.merge(d1)

enter image description here