python3 统计一个list的词频【附代码】

今天爱分享给大家带来 python3 统计一个list的词频【附代码】,希望能帮助到大家。

做统计机器学习经常需要统计,这里我来分享一下怎样统计一个list里面每个字符串的频率:

from collections import Counter
word_count=['I','am','from','China',',','I','Love','my','country','!','!','!']
 
counter = Counter(word_count)
dictionary=dict(counter)
# get to k most frequently occuring words
k=10
res=counter.most_common(k)
print(res)

输出为:

[('!', 3), ('I', 2), ('am', 1), ('from', 1), ('China', 1), (',', 1), ('Love', 1), ('my', 1), ('country', 1)]
原文链接:https://blog.itblood.com/1590.html,转载请注明出处。
0
我的乡村日常生活v0.3.3[PC+安卓/2.98G/更新] [神作RPG/AI汉化]
我的乡村日常生活v0.3.3[PC+安卓/2.98G/更新] [神作RPG/AI汉化]
1分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?