1. 程式人生 > 實用技巧 >050 例項12-政府工作報告詞雲

050 例項12-政府工作報告詞雲

目錄

一、"政府工作報告詞雲"問題分析

1.1 問題分析

直觀理解政策檔案

  • 需求:對於政府工作報告等政策檔案,如何直觀理解?
  • 體會直觀的價值:生成詞雲 & 優化詞雲

政府工作報告等檔案 --> 有效展示的詞雲

《決勝全面建成小康社會 奪取新時代中國特色社會主義偉大勝利》—— 在中國共...第十九次全國代表大會上的報告(2017年10月18日)習大大:想要《新時代中國特色社會主義》文字內容的可以加我微信:chenyoudea

《中共中央 國務院關於實施鄉村振興戰略的意見》 —— 2018一號檔案(2018年01月02日)中共中央 國務院:想要《關於實施鄉村振興戰略的意見》文字內容的可以加我微信:chenyoudea

二、"政府工作報告詞雲"例項講解(上)

2.1 政府工作報告詞雲

基本思路

  • 步驟1:讀取檔案、分詞整理
  • 步驟2:設定並輸出詞雲
  • 步驟3:觀察結果,優化迭代

2.2 新時代中國特色社會主義

# GovRptWordCloudv1.py
import jieba
import wordcloud

f = open("新時代中國特色社會主義.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png"
)

2.3 2018年一號檔案

# GovRptWordCloudv1.py

import jieba
import wordcloud

f = open("關於實施鄉村振興戰略的意見.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)
w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png")

2.4 新時代中國特色社會主義

# GovRptWordCloudv1.py
import jieba
import wordcloud

f = open("新時代中國特色社會主義.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png")

2.5 2018年一號檔案

# GovRptWordCloudv1.py

import jieba
import wordcloud

f = open("關於實施鄉村振興戰略的意見.txt", "r", encoding="utf-8")
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white")
w.generate(txt)
w.to_file("grwordcloud.png")

三、"政府工作報告詞雲"例項講解(下)

3.1 政府工作報告詞雲

更有形的詞雲

3.2 五角星

# GovRptWordCloudv2.py 
import jieba
import wordcloud

from imageio import imread 
mask = imread("fivestart.png")

f = open("新時代中國特色社會主義.txt", "r", encoding="utf-8") 
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white", mask=mask)
w.generate(txt)
w.to_file("grwordcloud.png")

3.3 中國地圖

# GovRptWordCloudv2.py 
import jieba
import wordcloud

from imageio import imread 
mask = imread("chinamap.jpg?x-oss-process=style/watermark")

f = open("新時代中國特色社會主義.txt", "r", encoding="utf-8") 
t = f.read()
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)

w = wordcloud.WordCloud(font_path = "/Library/Fonts/Heiti.ttc",width = 1000, height = 700, background_color = "white", mask=mask)
w.generate(txt)
w.to_file("grwordcloud.png")

四、"政府工作報告詞雲"舉一反三

4.1 擴充套件能力

  • 瞭解wordcloud更多引數,擴充套件詞雲能力
  • 特色詞雲:設計一款屬於自己的特色詞雲風格
  • 更多檔案:用更多檔案練習詞雲生成