Sorry if this is a similar question, I tried to find one that could answer my specific use-case but I only found ones that give exact matches between dataframes.
I have 2 pandas data frames of descriptions:
df1:
Description
i had lunch
going to the airport
buying a suitcase
df2:
Description
buying lunch
airport travel
owning a car
I'd like to filter and/or count how many times df2
has a matching word that appears in any row of df1
so for example df2
has the words 'lunch' and 'airport' and those single words appear in df1
, so I would like to pull out and count the rows in df2
that have that match.
So my output is just a filtered df2
based on single word matches in df1
.
Example output filtered would be:
df2:
Description
buying lunch
airport travel
Is there a way I can do this with pandas dataframes?
Example input data:
d = {'Description': ['i had lunch', 'going to the airport', 'buying a suitcase']}
df1 = pd.DataFrame(data=d)
d = {'Description': ['buying lunch', 'airport travel', 'owning a car']}
df2 = pd.DataFrame(data=d)