python统计段落单词词频_使用Python统计文件中词频,并且生成词云
wordcloud
Table of Contents
1 怎樣使用Python產(chǎn)生詞云
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
# Now, There is no 'word.txt' under this path
path_txt = "/home/alan/Desktop/word.txt"
f = open(path_txt, 'r', encoding = 'UTF-8').read()
cut_text = " ".join(jieba.cut(f))
wordcloud = WordCloud(
font_path = "/home/alan/.local/share/fonts/STKAITI.TTF",
background_color="white",
width=1000,
height = 800
).generate(cut_text)
plt.imshow(wordcloud, interpolation = "bilinear")
plt.axis("off")
plt.show()
總體思路:
導(dǎo)入文章
"jieba"分詞
統(tǒng)計(jì)詞頻
生成并繪制詞云
標(biāo)簽:plt,Python,wordcloud,cut,詞云,path,詞頻,txt
來(lái)源: https://www.cnblogs.com/alango/p/10364436.html
總結(jié)
以上是生活随笔為你收集整理的python统计段落单词词频_使用Python统计文件中词频,并且生成词云的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
                            
                        - 上一篇: 万紫千红春满园的上一句 这句话什么意思
 - 下一篇: 怎么判断尾插小板坏了