Skip to content

Instantly share code, notes, and snippets.

@liannewriting
Created September 6, 2020 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liannewriting/3b2962b65342902dc31b73545fb13a64 to your computer and use it in GitHub Desktop.
Save liannewriting/3b2962b65342902dc31b73545fb13a64 to your computer and use it in GitHub Desktop.
Twitter sentiment analysis python
# stopwords do not appear in the wordcloud.
stopwords = STOPWORDS.copy()
stopwords.update(['http', 'https', 'co', 'starbuck', 'starbucks']) # add some additional stopwords.
# make all the text lowercase and combine everything together.
all_txt = [txt.lower() for txt in df_starbucks['full_text'].to_list()]
all_txt = ' '.join(all_txt)
# create and plot the wordcloud.
wordcloud = WordCloud(stopwords=stopwords, background_color="white", width=800, height=600).generate(all_txt)
plt.figure(figsize=(15,10))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment