小編這次要給大家分享的是如何用Python詞云分析政府工作報(bào)告關(guān)鍵詞,文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
前言
十三屆全國(guó)人大三次會(huì)議作了政府工作報(bào)告。這份政府工作報(bào)告僅有10500字左右,據(jù)悉是改革開放40年以來最短的一次。受到疫情影響,今年的兩會(huì)會(huì)議適當(dāng)縮短,政府工作報(bào)告也大幅壓縮,體現(xiàn)了“實(shí)干為要”的理念。那么,這份政府工作報(bào)告突出強(qiáng)調(diào)了哪些關(guān)鍵詞呢?我們其實(shí)可以基于Python技術(shù)進(jìn)行詞頻分析和詞云制作!
import matplotlib.pyplot as plt#繪圖庫(kù) import jieba from wordcloud import WordCloud # 讀入文本數(shù)據(jù) fp = open(r'D:\爬蟲下載\2020年政府工作報(bào)告.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())#轉(zhuǎn)成列表 hist.sort(key=lambda x:x[1],reverse=True) # print(hist) #調(diào)試輸出 for i in range(20): # print(hist[i]) print('{:<10}{:>5}'.format(hist[i][0],hist[i][1]))#左對(duì)齊10,右對(duì)齊5個(gè)長(zhǎng)度