I have a list keywords and a dataframe:
keywords=['chair','table', 'fan']
Description
The table is 6 inches long
The fan is really good
The table fan is cheap
The chair is broken
The chair is on the table
I want to search the list of keywords and create a new column with which keyword from the list is present in the Description column.
Description Keyword
The table is 6 inches long table
The fan is really good fan
The table fan is cheap table, fan
The chair is broken chair
The chair is on the table chair, table
I have searched for a few solutions, but none of them seems to work. I tried the following code on my own:
for i in word_set:
for x in range(0, len(df)):
if(df['Event Message'][x] in (i)):
df['word'] = i
But obviously the time complexity is too high and is taking lot of time. Any help would be appreciated.