简体   繁体   English

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

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

the code below is written in python in Jupyter notebook.下面的代码是用 Jupyter notebook 的 python 编写的。

Function to Create WordCloud 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))

Creating wordcloud for tweet analysis为推文分析创建 wordcloud

create_wordcloud(tw_list["text"].values)

This is the error generated这是产生的错误

<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'

download cloud.png and wc.png files from the following GitHub https://github.com/yalinyener/TwitterSentimentAnalysis从以下 GitHub https://github.com/yalinyener/TwitterSentimentAnalysis下载 cloud.png 和 wc.png 文件

then upload to your source location然后上传到您的源位置

暂无
暂无

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

相关问题 我正在尝试显示 wordcloud 图像,但出现 ValueError: We need at least 1 word to plot a word cloud, got 0 - i' m trying to display a wordcloud image but I'm getting ValueError: We need at least 1 word to plot a word cloud, got 0 Python WordCloud 代码中的导入错误。他们说没有名为 wordcloud 的模块 - import error in Python WordCloud code.they said no module called wordcloud 试图编写一个计数游戏,这个错误不断发生,我不知道如何解决它(真的是初学者级别) - Trying to code a counting game, this error keeps occuring and I'm not sure how to solve it (really beginner level) 尝试使用Selenium 2与Python绑定,但我收到导入错误 - Trying to use Selenium 2 with Python bindings, but I'm getting an import error 我正在尝试通过Python中的“localhost”发送电子邮件,但它一直给我一个“错误61” - I'm trying to send email through 'localhost' in Python but it keeps giving me an “Error 61” 为什么我的代码中出现这个Python错误? - How come I'm getting this Python error in my code? 我正在尝试使用python实现strassen的算法,但出现错误 - I'm trying to implement strassen's algorithm using python and I'm getting a error 我正在尝试标准化我的属性,但由于 Python 找不到它而出现标准缩放器错误 - I'm trying to standardize my attribute but I'm getting standard scaler error because Python can not find it 我正在尝试实现:np.maximum.outer in Python 3x 但我收到此错误:NotImplementedError - I´m trying to implement: np.maximum.outer in Python 3x but I´m getting this error: NotImplementedError 我正在尝试在 python 中使用 HTML img 标签发送邮件,但出现以下错误 - I'm trying to use HTML img tag in python to send a mail, but I'm getting the following error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM