ValueError: We need at least 1 word to plot a word cloud, got 0.
这句话的意思就是我们至少要得到一个词才能绘制词云,说明读取.txt文件并没有成功。

打开.txt文件—文件—另存为—选择编码(UTF-8)—替换原来的》txt文件就OK了

用Python绘制词云,读取.txt文件的时候报错:ValueError: We need at least 1 word to plot a word cloud, got 0.

用Python绘制词云,读取.txt文件的时候报错:ValueError: We need at least 1 word to plot a word cloud, got 0.

用Python绘制词云,读取.txt文件的时候报错:ValueError: We need at least 1 word to plot a word cloud, got 0.

最后就可以成功运行了,我贴一下我的代码的运行后的结果图

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( \
    width = 1000, height = 700,\
    background_color = "white",
    font_path = "msyh.ttc"    
    )
w.generate(txt)
w.to_file("grwordcloud.png")

用Python绘制词云,读取.txt文件的时候报错:ValueError: We need at least 1 word to plot a word cloud, got 0.

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-08-04
  • 2022-12-23
  • 2021-04-18
  • 2022-01-14
  • 2021-10-18
  • 2022-12-23
猜你喜欢
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-01-28
相关资源
相似解决方案