首页 > 其他 > 详细

中文词频统计

时间:2017-09-29 21:47:33      阅读:269      评论:0      收藏:0      [点我收藏+]

中文分词

1.下载一中文长篇小说,并转换成UTF-8编码。

2.使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。

3.排除一些无意义词、合并同一词。

4.对词频统计结果做简单的解读。


import jieba
s=open(‘xiaoshuo.txt‘,‘r‘,encoding=‘utf-8‘)

#读入待分析的字符串
str=s.read()
s.close()

for i in ‘,。!、 \n “ ” ;‘:
str=str.replace(i,‘‘)

words=jieba.cut(str)
word=set(words)

#计数字典
dic={}
for i in word:
if len(i)>1:
dic[i]=str.count(i)
str=list(dic.items())

#排序
str.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
print(str[i])
 

技术分享

中文词频统计

原文:http://www.cnblogs.com/0020l/p/7612752.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!