Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

python contains multiple strings pandas

string_list = pd.Series(['dog', 'doggy', 'doggo', 'canine', 'kitten', 'cat', 'kitty', 'feline' ])
matches = 'dog|kit' # you can have multiple validations in one string with the | operator
print(string_list[ string_list.str.contains(matches)])
#0       dog
#1     doggy
#2     doggo
#4    kitten
#6     kitty
Comment

PREVIOUS NEXT
Code Example
Python :: how to append rows to a numpy matrix 
Python :: how to spread an array in python 
Python :: module pygame has no member 
Python :: pandas reciprocal 
Python :: href in selenium 
Python :: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. 
Python :: python randomized selection 
Python :: load from np file py 
Python :: decode url python 
Python :: Find the value in column in pandas 
Python :: Traceback (most recent call last): File "/usr/bin/pip", line 9, in <module from pip import main 
Python :: sns seaborn set theme 
Python :: django install whitenoise 
Python :: python input comma separated values 
Python :: pandas drop values from column 
Python :: python WhatsApp messaging spammer 
Python :: python os output to variable 
Python :: python printing date 
Python :: django rest framework configuration 
Python :: python plot two lines on same graph 
Python :: clear console in python 
Python :: RandomForestRegressor import 
Python :: discord identity python html avatar 
Python :: how to split a list to 1000 items python 
Python :: check palindrome in python using recursion 
Python :: calculate highest frequency or mode in pandas dataframe 
Python :: jupyter no output cell 
Python :: discord command addrole python 
Python :: extract zip file python 
Python :: if a number times a number is true python 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =