六云

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

下载一长篇中文文章。

从文件读取待分析文本。

news = open('gzccnews.txt','r',encoding = 'utf-8')

安装与使用jieba进行中文分词。

pip install jieba

import jieba

list(jieba.lcut(news))

生成词频统计

排序

排除语法型词汇,代词、冠词、连词

输出词频最大TOP20

import jieba

article = open('test.txt','r').read()
dele = {'','','','','','','','',' ','','',''}
jieba.add_word('大数据')
words = list(jieba.cut(article))
articleDict = {}
articleSet = set(words)-dele
for w in articleSet:
    if len(w)>1:
        articleDict[w] = words.count(w)

articlelist = sorted(articleDict.items(),key = lambda x:x[1], reverse = True)

for i in range(10):
    print(articlelist[i])

运行截图:

 

posted on 2018-03-28 19:50  流XC  阅读(11410)  评论(0编辑  收藏  举报