How can I create a new column in a pandas data frame by following these conditions?
if column 'Ex' match with one of the elements in this list l=['cnn', 'nba', 'agi', 'apple'] then:
Create the new column named S, having value 1 for those elements in a list.
The Original data frame:
I would approach the problem as follows:
df['S']=df['Ex'].apply(lambda x: any([k in x for k in l]))
to check if a row matches (I do not want a 'contains' condition) one of the values within l. I do not know how to assign the values 1 or 0, but I think, I need to add an if statement.