How to test if a string contains one of the substrings in a list, in pandas?
In the link above, many people suggested the chosen answer, which is...
searchfor = ['og', 'at']
s[s.str.contains('|'.join(searchfor))]
In my case, I have 300+ searchfor in the list. and I also have several thousand rows in s. Using the way above, I can quickly check if any of the keyword is in the column. However, I am not sure how to create another column in s that shows what searchfor words are in the column.
For example, if
s.loc[0,'fulltext'] = 'ff og at ew'
, then
s.loc[0, 'found_keyword'] = ['og, 'at']
if
s.loc[1, 'fulltext'] = 'ff og ew gg'
, then
s.loc[1, 'found_keyword'] = ['og']
Any recommendation will be very appreciated.