繁体   English   中英

我正在尝试使用此 python 代码创建 wordcloud,但不断出现错误

[英]I'm trying to create a wordcloud with this python code, but keeps getting error

下面的代码是用 Jupyter notebook 的 python 编写的。

Function 创建词云

def create_word(text):

    mask = np.array (Image.open("cloud.png"))
    stopwords = set (STOPWORDS)
    wc= WordCloud(background_color="white",
                 mask= mask,
                 max_words=3000,
                 stopwords=stopwords,
                 repeat=True)
    wc.generate(str(text))
    wc.to_file("wc.png")
    print("Word Cloud Saved Successfully")
    path="wc.png"
    display(Image.open(path))

为推文分析创建 wordcloud

create_wordcloud(tw_list["text"].values)

这是产生的错误

<ipython-input-83-57370aac7740> in create_wordcloud(text)
      3
      4 def create_wordcloud(text):
----> 5     mask = np.array(Image.open("cloud.png"))
      6     stopwords = set(STOPWORDS)
      7     wc = WordCloud(background_color="white",

 ~\anaconda3\lib\site-packages\PIL\Image.py in open(fp, mode, formats)

FileNotFoundError: [Errno 2] No such file or directory: 'cloud.png'

从以下 GitHub https://github.com/yalinyener/TwitterSentimentAnalysis下载 cloud.png 和 wc.png 文件

然后上传到您的源位置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM