Skip to content Skip to sidebar Skip to footer

Singular And Plural Phrase Matching In Pandas

I have a pandas Series and another sentences Dataframe as follows(only a summary of the data is added here). #df 0 1 teaspoon vanilla extract 1 2 eggs 2 1 cup chopped walnuts 3

Solution 1:

I don't know what your column names are for the first df, in my example they are both ingredients but the following would work:

In [256]:
df1['ingredients'].apply(lambda x: any(df['ingredients'].str.lower().str.contains(x.lower())))

Out[256]:
index
0True1True2True3True
Name: ingredients, dtype: bool

Essentially this performs a reverse lookup, we iterate over the ingredients series using apply and then test for membership of this ingredient in the whole df using contains this will handle plurals in this case.

Post a Comment for "Singular And Plural Phrase Matching In Pandas"