Is there any function that would be the equivalent of a combination of df.isin() and df[col].str.contains()?
For example, say I have the series s = pd.Series(['cat','hat','dog','fog','pet']), and I want to find all places where s contains any of ['og', 'at'], I would want to get everything but 'pet'.
I have a solution, but it's rather inelegant:
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?
pd.Series.str.contains. If performance is an issue, then this may be worth investigating.pd.Series.str.endswithwith a tuple argument: pandas.pydata.org/docs/reference/api/…