I have a pandas dataframe like this
and I have a list of keywords
branches_of_sci = ['bio', 'chem', 'physics']
So What I want to do is create a new column and add new keywords with a separation of coma or anything else
I was able to do this temporary
for tok in branches_of_sci:
df[branch] = df.astype(str).sum(axis=1).str.contains(branch)
but it generates new column for every keyword, Can I just create a new single column where all keywords found are stored.
The marked duplicate answer only finds a single keyword but what if multiple keywords match then it fails.
df['Col 3'] = df['Col 2'].str.extract("(" + "|".join(List1) +")", expand=False)