I have a list of strings
list_ = ['abc', 'def', 'xyz']
And I have a df with column CheckCol, that I want to check if the values in CheckCol contains any of the whole of substring of the list element.
If it does, I want to extract the original value into a new column NewCol.
CheckCol
'a'
'ab'
'abc'
'abc-de'
Into
# What I want
CheckCol NewCol
'a'
'ab'
'abc' 'abc'
'abc-de' 'abc-de'
My following codes, however, only recognize the exact full string, but not the substrings I was looking for.
df['NewCol'] = np.where(df['CheckCol'].isin(list_), df['CheckCol'], '')
And gives
# What I get
CheckCol NewCol
'a'
'ab'
'abc' 'abc'
'abc-de'
Edits: Changed list to list_