Python实例12:政府工作报告词云
基本思路:
- 读取文件、分词整理;
- 设置并输出词云;
- 观察结果,优化迭代;




# GovRptWordCloudv1.py
import jieba
import wordcloud
f = open("E:\\python\\learn\\2020政府工作报告.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(width=1000, font_path="msyh.ttc", height=700, background_color="white",)
w.generate(txt)
w.to_file("E:\\python\\learn\\2020政府工作报告.png")
<wordcloud.wordcloud.WordCloud at 0x2baf2f1c048>
# GovRptWordCloudv2.py
import jieba
import wordcloud
from scipy.misc import imread
mask = imread("E:\\python\\learn\\fivestart.png")
f = open("E:\\python\\learn\\2020政府工作报告.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(mask=mask, width=1000, font_path="msyh.ttc", height=700, background_color="white",)
w.generate(txt)
w.to_file("E:\\python\\learn\\2020政府工作报告2.png")
D:\anaconda\lib\site-packages\ipykernel_launcher.py:5: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
"""
<wordcloud.wordcloud.WordCloud at 0x2baf2efef60>
点赞,关注,收藏👍,➕,👀点赞,关注,收藏👍,➕,👀点赞,关注,收藏👍,➕,👀
😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘
💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪💪

Python政府工作报告词云制作
本文介绍了使用Python进行政府工作报告的词云制作过程,包括读取文件、分词处理、生成词云及优化迭代,旨在展示Python在文本可视化方面的能力。
2553

被折叠的 条评论
为什么被折叠?



