0

I have a dataset(Dataframe) with multiple sentences/words in a Row. I want to extract those row data which consists of the given Specific Keyword. The Dataset is Stated below

Dataframe

My query is to Extract those rows which contain Multiple input words(Multiple Strings) that are entered by the user.

PFB, example for a Single String

Single String

I used the below code for Multiple Strings with LOGICAL "OR" operator using '|'.

Multi String

My Main Query is to Find the words with "AND" Operator. I want to search for rows containing ["Product", "Jumbo", "Peanut"] and only the 6th row satisfies it, So is there any logic like the above to show the rows containing the search inputs.

Thanks for your time!

Ravi
  • 187
  • 1
  • 1
  • 7

1 Answers1

2

Try using this regex expression:

print(df[df['Text'].str.contains(r'(?=.*Product)(?=.*Jumbo)(?=.*Peanut)')])
U13-Forward
  • 69,221
  • 14
  • 89
  • 114