I want to do a keyword search on pandas dataframe, adding each keyword as a column to the dataset, and marking "True" rows of data that contain the keyword.
A piece of code that does it nicely is this:
stocks = ['Microsoft','Apple', 'Amazon']
for stock in stocks:
df[stock] = df.astype(str).sum(axis=1).str.contains(stock)
However, this loops through the entire dataset once for each keyword. I would like to do the same thing in one iteration (i.e. each row is checked for the presence of the keywords only once), because my dataset is large.
The expected result is this:
Any help will be appreciated
EDIT: I am getting a Memory Error.