使用Python统计文件中词频,并且生成词云

wordcloud

Table of Contents

1 怎样使用Python产生词云

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()

总体思路:

  • 导入文章
  • "jieba"分词
  • 统计词频
  • 生成并绘制词云
上一篇:python生成词云笔记


下一篇:Java-集合=第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: List list = new ArrayList(); list.add(new A