check if string in pandas dataframe column is in list
Post date: Sep 17, 2014 2:38:34 PM
check if string in pandas dataframe column is in list
The str.contains
method accepts a regular expression pattern:
In [11]: pattern = '|'.join(mylist) In [12]: pattern Out[12]: 'dog|cat|fish' In [13]: frame.a.str.contains(pattern) Out[13]: 0 True 1 False 2 True Name: a, dtype: bool
From stackoverflow