Pandas比较两个匹配文本的列并打印完整的匹配行

时间:2016-10-04 23:55:16

标签: python pandas

我希望从一个df中获取一个哈希,并在另一个df.hash列中找到该哈希并打印匹配的完整行。

DF1: hash 11dd7da7faa0130dac2560930e90c8b1 11dd7da7faa0130dac2560930e90c8b2 11dd7da7faa0130dac2560930e90c8b3 11dd7da7faa0130dac2560930e90c8b4 DF2: filepath hash C:\windows 11dd7da7faa0130dac2560930e90c8b5 C:\Temp 11dd7da7faa0130dac2560930e90c8b6 C:\foundya 11dd7da7faa0130dac2560930e90c8b1 C:\Windows\temp 11dd7da7faa0130dac2560930e90c8b2

预期产量: filepath hash C:\foundya 11dd7da7faa0130dac2560930e90c8b1 C:\Windows\temp 11dd7da7faa0130dac2560930e90c8b2 尝试失败: print(df2[['hash','filepath']][~df2['hash'].isin(df1)]) print(df2[['hash','filepath']][~df1.isin(df2['hash'])])

1 个答案:

答案 0 :(得分:1)

这里简单的合并怎么样?

df1.merge(df2, on ='hash', how ='inner')