中文词频统计

复制代码
import jieba


fo=open('aaa.txt','r',encoding = 'utf-8')

text=fo.read()
text2=list(jieba.lcut(text))

sign={'',' ','','我们', '', '他们', '我的', '他的', '你的', '', '', '','','','','','','','','?','','',\
           '','','','','','','','','','','','','','', '\n','(',')','','','','便','','','','','','那里',\
           '','一个','','','','','','','','','','','','','','','你们','',''}

text3={}
for i in text2:
    text3[i]=text3.get(i,0)+1

for i in sign:
    if i in text3:
        del text3[i]

text4 =sorted(text3.items(),key=lambda x:x[1],reverse=True)
for i in range(20):
    print(text4[i])
复制代码

posted @   172张智恒  阅读(79)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示