簡體   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