How to add extra stop words in addition to default stopwords in wordcloud?
I would like to add certain words to the default stopwords list used in wordcloud. This is the code I used.
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()
When i use this custom stop_words variable, words like is, was ,the are all interpreted and displayed as highly frequent words but when i use the default stopwords list (no stopwords argument) then there are so many other words that are displayed as highly frequent. How do i add my custom stop_words variable along with the default stopwords list to my word cloud.
python matplotlib data-analysis stop-words word-cloud
add a comment |
I would like to add certain words to the default stopwords list used in wordcloud. This is the code I used.
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()
When i use this custom stop_words variable, words like is, was ,the are all interpreted and displayed as highly frequent words but when i use the default stopwords list (no stopwords argument) then there are so many other words that are displayed as highly frequent. How do i add my custom stop_words variable along with the default stopwords list to my word cloud.
python matplotlib data-analysis stop-words word-cloud
add a comment |
I would like to add certain words to the default stopwords list used in wordcloud. This is the code I used.
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()
When i use this custom stop_words variable, words like is, was ,the are all interpreted and displayed as highly frequent words but when i use the default stopwords list (no stopwords argument) then there are so many other words that are displayed as highly frequent. How do i add my custom stop_words variable along with the default stopwords list to my word cloud.
python matplotlib data-analysis stop-words word-cloud
I would like to add certain words to the default stopwords list used in wordcloud. This is the code I used.
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()
When i use this custom stop_words variable, words like is, was ,the are all interpreted and displayed as highly frequent words but when i use the default stopwords list (no stopwords argument) then there are so many other words that are displayed as highly frequent. How do i add my custom stop_words variable along with the default stopwords list to my word cloud.
python matplotlib data-analysis stop-words word-cloud
python matplotlib data-analysis stop-words word-cloud
asked Jan 1 at 17:20
CommandCommand
608
608
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just append your list to the built-in STOPWORDS list:
From the wordcloud documentation:
stopwords : set of strings or None. The words that will be eliminated.
If None, the build-in STOPWORDS list will be used.
So you can simply append STOPWORDS to your custom list and use it
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()
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
add a comment |
Just get the list of original stop words with from wordcloud import STOPWORDS
then append your list. Like this [STOPWORDS.add(n) for n in custon_stop_words]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997443%2fhow-to-add-extra-stop-words-in-addition-to-default-stopwords-in-wordcloud%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just append your list to the built-in STOPWORDS list:
From the wordcloud documentation:
stopwords : set of strings or None. The words that will be eliminated.
If None, the build-in STOPWORDS list will be used.
So you can simply append STOPWORDS to your custom list and use it
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()
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
add a comment |
Just append your list to the built-in STOPWORDS list:
From the wordcloud documentation:
stopwords : set of strings or None. The words that will be eliminated.
If None, the build-in STOPWORDS list will be used.
So you can simply append STOPWORDS to your custom list and use it
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()
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
add a comment |
Just append your list to the built-in STOPWORDS list:
From the wordcloud documentation:
stopwords : set of strings or None. The words that will be eliminated.
If None, the build-in STOPWORDS list will be used.
So you can simply append STOPWORDS to your custom list and use it
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()
Just append your list to the built-in STOPWORDS list:
From the wordcloud documentation:
stopwords : set of strings or None. The words that will be eliminated.
If None, the build-in STOPWORDS list will be used.
So you can simply append STOPWORDS to your custom list and use it
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()
edited Jan 1 at 18:11
answered Jan 1 at 18:07
HakunaMaDataHakunaMaData
730418
730418
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
add a comment |
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
This throws an error because STOPWORDS is a set
– Deejpake
Jan 1 at 18:10
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Cast it to a list or the custom list to a set. Edited the code.
– HakunaMaData
Jan 1 at 18:11
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
Works thank you. @HakunaMaData
– Command
Jan 1 at 18:16
add a comment |
Just get the list of original stop words with from wordcloud import STOPWORDS
then append your list. Like this [STOPWORDS.add(n) for n in custon_stop_words]
add a comment |
Just get the list of original stop words with from wordcloud import STOPWORDS
then append your list. Like this [STOPWORDS.add(n) for n in custon_stop_words]
add a comment |
Just get the list of original stop words with from wordcloud import STOPWORDS
then append your list. Like this [STOPWORDS.add(n) for n in custon_stop_words]
Just get the list of original stop words with from wordcloud import STOPWORDS
then append your list. Like this [STOPWORDS.add(n) for n in custon_stop_words]
edited Jan 1 at 18:10
answered Jan 1 at 18:02
DeejpakeDeejpake
1157
1157
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997443%2fhow-to-add-extra-stop-words-in-addition-to-default-stopwords-in-wordcloud%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown