Search code examples
pandasdataframemappingcontains

Retrieve Pandas Rows which Contain Multiple Text Query in Any Order


suppose I have this dataframe table with four rows:

Text
-----
there is an issue
very enormous issue
the issue is difficult
you think

Is there any way in Pandas to retrieve rows which contains "issue" or "is" in any order or maybe mapping function? Therefore, the result should be like this:

df[df['Text'].somefunction('issue, is')

Text
-----
there is an issue
very enormous issue
the issue is difficult

All three of the rows contain "is" or "issue" in any order. Therefore, you could also write in the function somefunction('is', 'issue') because the exact position is not matter. I tried with Pandas contain but it returns the exact row according to query ('the issue is difficult'). Any help appreciated.


Solution

  • Try:

    df[df['Text'].str.contains('is|issue')
    

    Documentation