简体   繁体   English

如何从 jupyter notebook 中的词云中删除自定义词

[英]how to remove custom words from word cloud in jupyter notebook

wordcloud = WordCloud(background_color="white",width=1600,height=800).generate(' '.join(df1['text'].tolist()))
plt.figure(figsize=(20,10), facecolor='k')
plt.imshow(wordcloud)

The word cloud that gets shown has data that I don't think is relevant, such as user, need, anyone, issue, trying, and some other words.显示的词云包含我认为不相关的数据,例如用户、需要、任何人、问题、尝试和其他一些词。 I have already removed stop words, but how can I remove a custom list of words from the word cloud?我已经删除了停用词,但是如何从词云中删除自定义的词列表? This is a word cloud from data I scraped from slack, and I want it to representative of questions people are asking in the channel that are more related to things like email, server, outlook, duo etc.这是我从 slack 中抓取的数据中的词云,我希望它能够代表人们在频道中提出的与电子邮件、服务器、Outlook、二重奏等更相关的问题。 在此处输入图像描述

If you are using the wordcloud package, I think there isn't an option to remove user-provided custom words.如果您使用wordcloud包,我认为没有删除用户提供的自定义词的选项。

If there is a list of words you want to remove, I think you can remove them from df1 before fitting the word cloud.如果有要删除的单词列表,我认为您可以在拟合词云之前将它们从df1中删除。

You can do it like this:你可以这样做:

  • get the list of the default stopwords获取默认停用词列表
  • add your custom stopwords添加您的自定义停用词
  • convert to a set转换为集合
  • use in WordClould在 WordClould 中使用
w = WordCloud()
stop_words = list(w.stopwords)
custom_stop_words = ['user', 'need']
stop_words = set(stop_words + custom_stop_words)

wordcloud = WordCloud(background_color="white",width=1600,height=800, stopwords=stop_words).generate(' '.join(df1['text'].tolist()))
plt.figure(figsize=(20,10), facecolor='k')
plt.imshow(wordcloud)

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

相关问题 如何从 Jupyter 笔记本中删除意外的 CSS? - How to remove accidental CSS from a Jupyter notebook? 如何从 jupyter 笔记本中删除停用的 conda 环境名称? - How to remove inactivate conda environment names from jupyter notebook? 为什么词云的 output 在 jupyter notebook 和我的 flask 应用程序中不同? - why output of word cloud is different in jupyter notebook and my flask app? 如何从相对目录(在 Jupyter 笔记本中)加载自定义单元格魔法? - How to load custom cell magic from a relative directory (in Jupyter notebook)? 如何在云中运行jupyter笔记本幻灯片? - How to run jupyter notebook slideshows in a cloud? 如何从 Google Cloud AI Jupyter Notebook(Python) 连接到 Google Cloud Platform Data Storage? - How to connect to Google Cloud Platform Data Storage from Google Cloud AI Jupyter Notebook(Python)? 如何从Python中的标记词生成词云? - How can I generate a word cloud from tokenized words in Python? 如何在 GCP 的 Jupyter Notebook 中安装自定义库? - How to install a custom libarry in Jupyter notebook of GCP? 如何从托管在外部服务器(谷歌云计算实例)上的 Jupyter Notebook 导出 fast.ai model? - How to export fast.ai model from Jupyter Notebook hosted on external server(google cloud compute instance)? Jupyter 笔记本定制服务 - Jupyter Notebook Custom Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM