Python 自然语言处理(一)字频统计
生活随笔
收集整理的這篇文章主要介紹了
Python 自然语言处理(一)字频统计
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import jieba
txt = open("lg.txt", "r", encoding="gb18030").read()import collectionstxt1 = txt
txt1 = txt1.replace('\n', '') # 刪掉換行符
txt1 = txt1.replace(',', '') # 刪掉逗號(hào)
txt1 = txt1.replace('。', '') # 刪掉句號(hào)
mylist = list(txt1)
mycount = collections.Counter(mylist)
for key, val in mycount.most_common(10): # 有序(返回前10個(gè))print(key, val)
38618
了 21157
. 20313
的 15604
不 14958
一 12107
: 11710
來 11405
道 11029
“ 10983
總結(jié)
以上是生活随笔為你收集整理的Python 自然语言处理(一)字频统计的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OnnxRuntime 性能调优
- 下一篇: c++ 新建一个数组