Created
August 27, 2020 14:50
-
-
Save Ram-N/0aebf358d91c75cdc11e672d5a1b204e to your computer and use it in GitHub Desktop.
Create a Simple Wordcloud using Donald Trump's Tweets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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