Here's my dataframe
CATEGORY BRAND
0 Noodle Anak Mas
1 Noodle Anak Mas
2 Noodle Indomie
3 Noodle Indomie
4 Noodle Indomie
23 Noodle Indomie
24 Noodle Mi Telor Cap 3
25 Noodle Mi Telor Cap 3
26 Noodle Pop Mie
27 Noodle Pop Mie
...
I already make sure that df type is string, my code is
df = data[['CATEGORY', 'BRAND']].astype(str)
import collections, re
texts = df
bagsofwords = [ collections.Counter(re.findall(r'w+', txt))
for txt in texts]
sumbags = sum(bagsofwords, collections.Counter())
When I call
sumbags
The output is
Counter({'BRAND': 1, 'CATEGORY': 1})
I want all of the data count in sumbags, except the title, to make it clear something like
Counter({'Noodle': 10, 'Indomie': 4, 'Anak': 2, ....}) # because it is bag of words
I need every 1 word counts
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…