Python 自然语言处理(一)字频统计
生活随笔
收集整理的这篇文章主要介绍了
Python 自然语言处理(一)字频统计
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
import jieba
txt = open("lg.txt", "r", encoding="gb18030").read()import collectionstxt1 = txt
txt1 = txt1.replace('\n', '') # 删掉换行符
txt1 = txt1.replace(',', '') # 删掉逗号
txt1 = txt1.replace('。', '') # 删掉句号
mylist = list(txt1)
mycount = collections.Counter(mylist)
for key, val in mycount.most_common(10): # 有序(返回前10个)print(key, val)
38618
了 21157
. 20313
的 15604
不 14958
一 12107
: 11710
来 11405
道 11029
“ 10983
总结
以上是生活随笔为你收集整理的Python 自然语言处理(一)字频统计的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: OnnxRuntime 性能调优
- 下一篇: Python 画樱花(动态画+飘落效果+