Is there any function that would be equivalent to a combination of df.isin()and df[col].str.contains()?
For example, let's say I have a series s = pd.Series(['cat','hat','dog','fog','pet']), and I want to find all the places where sany of it contains ['og', 'at'], I would like to get everything except 'pet'.
I have a solution, but it's not quite elegant
searchfor = ['og', 'at']
found = [s.str.contains(x) for x in searchfor]
result = pd.DataFrame[found]
result.any()
Is there a better way to do this?
source
share