Skip to content Skip to sidebar Skip to footer

Pandas Find Common Matches Between 2 Dataframes

I have 2 dataframes and I want to find common matches based on a column (tld), once match has been found, I want to update column match as True. How to update column in destination

Solution 1:

Using isin to update:

df2.loc[df2.tld.isin(df1.tld),'match']=True
df2

Out[669]: 
  id           website company_name           tld  match
0  a  www.facebook.com     facebook  facebook.com   True
1  b         www.y.com     YahooInc         y.com  False
2  c         www.g.com       Google         g.com  False
3  d         www.g.com    GoogleInc         g.com  False
4  e  www.facebook.com  FacebookInc  facebook.com   True

Solution 2:

This will achieve what you want:

destination["match"] = destination["tld"].isin(source.tld)

Post a Comment for "Pandas Find Common Matches Between 2 Dataframes"