Answers for "dataframe str contains multiple"

1

pandas multiple string contains

# credit to Stack Overflow user in the source link

>>> df = pd.Series(['cat','hat','dog','fog','pet'])
>>> searchfor = ['og', 'at']
>>> df[df.str.contains('|'.join(searchfor))]

0    cat
1    hat
2    dog
3    fog
dtype: object
Posted by: Guest on May-18-2021
1

str.contains multiple strings

>>> searchfor = ['og', 'at']
>>> s[s.str.contains('|'.join(searchfor))]
0    cat
1    hat
2    dog
3    fog
dtype: object
Posted by: Guest on September-15-2020

Browse Popular Code Answers by Language