有没有这将是一个组合的等同的任何功能df.isin()和df[col].str.contains()?
例如,假设我有系列
s = pd.Series(['cat','hat','dog','fog','pet']),并且我想找到s包含的任何一个的所有地方['og', 'at'],那么我想得到除“宠物”以外的所有东西。
我有一个解决方案,但这很不雅致:
searchfor = ['og', 'at']
found = [s.str.contains(x) for x in searchfor]
result = pd.DataFrame[found]
result.any()
有一个更好的方法吗?
pd.Series.str.contains。如果性能是一个问题,那么这可能值得研究。