I have a problem to solve. I need to create new columns from given
key_words list and sum their occurrence in data frame.
key_words = [‘apple’, ‘animal’, ‘everyone’]
input data frame:
|1||Apple is a healthy fruit. Everyone should eat it.||..|
|2||Lion is a denagerous animal.||..|
|3||Everyone likes him.||..|
what I want to get:
|1||Apple is a healthy fruit. Everyone should eat it.||..||1||0||1|
|2||Lion is a dangerous animal.||..||0||1||0|
|3||Everyone likes him.||..||0||0||1|
any help much appreciated.
This will work for you
key_words = ['apple', 'animal', 'everyone'] for key in key_words: df[key] = df['description'].str.lower().str.count(key)