johnnyb
johnnyb

Reputation: 1825

Pandas Compare two columns matching text and printing full row of matching

I am looking to take a hash from one df and find that hash in another df.hash column and print the full row of the matches.

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

Expected output: filepath hash C:\foundya 11dd7da7faa0130dac2560930e90c8b1 C:\Windows\temp 11dd7da7faa0130dac2560930e90c8b2 Failed Attempts: print(df2[['hash','filepath']][~df2['hash'].isin(df1)]) print(df2[['hash','filepath']][~df1.isin(df2['hash'])])

Upvotes: 0

Views: 337

Answers (1)

ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19395

what about a simple merge here?

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

Upvotes: 1

Related Questions