python xx 文章词频统计

import jieba

txt = open(r'G:\txt\全面深化金融供给侧结构性改革.txt','r',encoding='utf-8').read()

words =jieba.lcut(txt)	# 精准切词
count={}

for word in words:
    if len(word) ==1:
        continue
    else:
        count[word]=count.get(word,0)+1

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

for i in range(20):
    word,count=result[i]
    print(word,':',count)
金融 : 19
服务 : 9
积极 : 9
金融风险 : 8
经济 : 7
发展 : 7
制度 : 7
金融业 : 6
发力 : 6
优化 : 6
机构 : 6
投资者 : 6
风险 : 5
金融服务 : 5
实体 : 5
国内 : 4
融资 : 4
三是 : 4
结构 : 4
提升 : 4

猜你喜欢

转载自blog.csdn.net/byakki/article/details/87929377