Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created Aug 27, 2020
Embed
What would you like to do?
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