Check if multiple substrings are in pandas dataframe [duplicate] Check if multiple substrings are in pandas dataframe [duplicate] pandas pandas

Check if multiple substrings are in pandas dataframe [duplicate]


You can use regex, where '|' is an "or" in regular expressions:

l = ['LIMITED','INC','CORP']  regstr = '|'.join(l)df['NAME'].str.upper().str.contains(regstr)

MVCE:

In [1]: import pandas as pdIn [2]: df = pd.DataFrame({'NAME':['Baby CORP.','Baby','Baby INC.','Baby LIMITED   ...: ']})In [3]: dfOut[3]:            NAME0    Baby CORP.1          Baby2     Baby INC.3  Baby LIMITEDIn [4]: l = ['LIMITED','INC','CORP']     ...: regstr = '|'.join(l)   ...: df['NAME'].str.upper().str.contains(regstr)   ...: Out[4]: 0     True1    False2     True3     TrueName: NAME, dtype: boolIn [5]: regstrOut[5]: 'LIMITED|INC|CORP'