I am hoping I am not creating a duplicate lol, but I spend more than hours looking for something similar to my questions :)
Said that, I have the following input:
foo= {"Brand":["loc doc poc",
"roc top mop",
"loc lot not",
"roc lot tot",
"loc bot sot",
"nap rat sat"] }
word_list=["loc","top","lot"]
df=pd.DataFrame(foo)
2 Desired Outputs
1 Dictionary with the occurrences stored
2 New column containing the number of occurrences for each row
#Outputs:
counter_dic={"loc":3,"top":1,"lot":2}
Brand count
0 loc doc poc 1
1 roc top mop 1
2 loc lot not 2
3 roc lot tot 1
4 toc bot sot 1
5 nap rat sat 0
The only idea that I had:
- Count how many times a set of terms occurs. I can create a bag of words and then filtering based on the dictionary keys?
If you find a similar question, this can be closed obviously.
I checked the following ones
Check If a String Is In A Pandas DataFrame