码迷,mamicode.com
首页 > 其他好文 > 详细

中文词频统计

时间:2018-03-29 00:09:23      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:ict   结果   统计   content   style   最大   print   技术分享   使用   

import jieba

f=open(novel.txt,r,encoding=utf-8)
content=f.read()
f.close()

symbol=‘‘‘。,“”!?\n();‘‘‘
for i in symbol:
    content=content.replace(i, )

# 使用jieba进行中文分词
contentList=list(jieba.cut(content))

# 生成词频统计
contentDict={}
for i in contentList:
    contentDict[i]=contentList.count(i)

# 排除语法型词汇,代词、冠词、连词
exclude={ ,,,,,,,,,,,,,,
         ,,,}
for i in exclude:
    del contentDict[i]

# 排序
contentDict=sorted(contentDict.items(),key=lambda e:e[1],reverse=True)

# 输出词频最大TOP20
for i in range(20):
    print(contentDict[i])

运行结果:

技术分享图片

 

中文词频统计

标签:ict   结果   统计   content   style   最大   print   技术分享   使用   

原文地址:https://www.cnblogs.com/ffde/p/8666602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!