170he

下载一长篇中文文章。

从文件读取待分析文本。

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

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

pip install jieba

import jieba

list(jieba.lcut(news))

生成词频统计

排序

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

输出词频最大TOP20

 

将代码与运行结果截图发布在博客上。

# -*- coding : UTF-8 -*-
# -*- author : onexiaofeng -*-
import jieba
jieba.add_word(\'路明非\')
news=open(\'longzu.txt\',\'r\',encoding=\'utf-8\')
notes=news.read()
notelist=list(jieba.lcut(notes))

Word={}
for i in set(notelist):    
    Word[i]=notelist.count(i)

delete_word={\'\',\' \',\'\',\'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\', \'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'?\',\'\',\'\',\
           \'\',\'使\',\'\',\'\',\'\',\'\',\'\',\'\',\'\', \'\n\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\
             \'\',\'\',\'\',\'便\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'使\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'\',\'一个\',\'\',\'\',\'\',\'就是\'}

for i in delete_word:        
    if i in Word:
        del Word[i]

sort_word = sorted(Word.items(), key= lambda d:d[1], reverse = True)  
for i in range(20):  
    print(sort_word[i])

 截图:

 

分类:

技术点:

相关文章: