Com*_*and 3 python matplotlib data-analysis stop-words word-cloud
我想将某些单词添加到 wordcloud 中使用的默认停用词列表中。当前代码:
all_text = " ".join(rev for rev in twitter_clean.text)
stop_words = ["https", "co", "RT"]
wordcloud = WordCloud(stopwords = stop_words, background_color="white").generate(all_text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
Run Code Online (Sandbox Code Playgroud)
当我使用自定义 stop_words 变量时,诸如 "is"、"was" 和 "the" 之类的词都被解释并显示为高频词。但是,当我使用默认的停用词列表(没有停用词参数)时,还有许多其他词显示为非常频繁。如何将我的自定义 stop_words 变量以及默认停用词列表添加到我的 wordcloud?
只需将您的列表附加到内置的 STOPWORDS 列表中:
来自 wordcloud 文档:
停用词:一组字符串或无。会被淘汰的话。如果没有,将使用内置的 STOPWORDS 列表。
因此,您可以简单地将 STOPWORDS 附加到您的自定义列表中并使用它
all_text = " ".join(rev for rev in twitter_clean.text)
stop_words = ["https", "co", "RT"] + list(STOPWORDS)
wordcloud = WordCloud(stopwords = stop_words, background_color="white").generate(all_text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11981 次 |
最近记录: |