Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created August 27, 2020 14:50
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 Ram-N/0aebf358d91c75cdc11e672d5a1b204e to your computer and use it in GitHub Desktop.
Save Ram-N/0aebf358d91c75cdc11e672d5a1b204e to your computer and use it in GitHub Desktop.
Create a Simple Wordcloud using Donald Trump's Tweets
import json
from wordcloud import WordCloud
import matplotlib.pyplot as plt
with open('data/trump_tweets/condensed_2018.json') as f:
data = json.load(f)
type(data), len(data)
text_list = []
for tweet in data:
text_list.append(tweet['text'])
# Combine all the Tweets into one giant String.
text = "".join(text_list)
#Do some light text manipulation. Drop "stop words" from appearing in the Wordcloud
drop_words = ['&', 't.co', ' now ', 'https']
for dw in drop_words:
text = text.replace(dw, "")
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
wordcloud = WordCloud(max_font_size=40).generate(text)
plt.figure()
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