小编这次要给大家分享的是如何用Python词云分析政府工作报告关键词,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

前言
十三届全国人大三次会议作了政府工作报告。这份政府工作报告仅有10500字左右,据悉是改革开放40年以来最短的一次。受到疫情影响,今年的两会会议适当缩短,政府工作报告也大幅压缩,体现了“实干为要”的理念。那么,这份政府工作报告突出强调了哪些关键词呢?我们其实可以基于Python技术进行词频分析和词云制作!
import matplotlib.pyplot as plt#绘图库
import jieba
from wordcloud import WordCloud
# 读入文本数据
fp = open(r'D:\爬虫下载\2020年政府工作报告.txt','r',encoding='utf-8')
content = fp.read()
# print(content)
#分词
words = jieba.lcut(content)
# 词频分析操作
data = {}
for word in words:
if len(word)>1:
if word in data:
data[word]+=1
else:
data[word]=1
# print(data)
#排序
hist = list(data.items())#转成列表
hist.sort(key=lambda x:x[1],reverse=True)
# print(hist)
#调试输出
for i in range(20):
# print(hist[i])
print('{:<10}{:>5}'.format(hist[i][0],hist[i][1]))#左对齐10,右对齐5个长度