I have a pandas dataframe which I want to check for substrings of a certain column. At the moment I have 30 lines of code of this kind:
df['NAME'].str.upper().str.contains('LIMITED')) |
(df['NAME'].str.upper().str.contains('INC')) |
(df['NAME'].str.upper().str.contains('CORP'))
They are all linked with an or
condition and if any of them is true, the name is the name of a company rather than a person.
But to me this doesn't seem very elegant. Is there a way to check a pandas string column for "does the string in this column contain any of the substrings in the following list" ['LIMITED', 'INC', 'CORP']
.
I found the pandas.DataFrame.isin function, but this is only working for entire strings, not for my substrings.