简体   繁体   中英

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.

Function to Create WordCloud

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

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

then upload to your source location

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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