Obama VS Trump Analysis
In this project, I scraped and analyzed President Obama and President Trump tweets using natural language processing (NLP).

Project Overview
The objective of this article is to analyze the tweets from Pres. Obama and Pres. Trump. I am interested to see the similarities and differences between 44th & 45th POTUS.
I will be using natural language processing (NLP) libraries (NLTK, TextBlob) to conduct text and sentiment analysis.
What is natural language processing?
Natural language processing is the ability of computers to understand human languages.
Useful applications/services built using NLP:
- Chatbots
- LawTech to automated contract review
- HRTech to analyze resumes and conduct background check
I like to read a summary and grasp the main points. Reading a 200 pages document is not enjoyable for me. NLP can help me extract keywords and give me an overview of the document.
Some notes:
- For the format of this article, I will always present the numbers and figures from Pres. Obama, then Pres. Trump.
- I am unable to collect all their tweets because I am unsure of which tweets are missing.
Pres. Obama tweets frequency:
Based on twitter, Pres. Obama has a total of 15.5k
tweets. I managed to data mine 13.2k
tweets. From this heatmap, I have checked these months without tweets, unfortunately, they do not account for the missing tweets.

Pres. Trump tweets frequency:
Based on twitter, Pres. Trump has a total of 37.2k
tweets. I managed to data mine 33.9k
tweets.

Tweet frequency comparison:
Pres. Trump tweet more than Pres. Obama
Pres. Obama metrics overview:
Metrics overview refers to replies, retweets and likes Statistics


Pres. Trump metrics overview:


Metrics overview comparison:
In terms of average/mean, Pres. Trump has a stronger social media presence as compared to Pres. Obama.
However, in terms of maximum, Pres. Obama (1,711,231
retweets; 4,591,647
likes) are higher than that of Pres. Trump (265,230
retweets; 610,866
likes)
Pres. Obama sentiment overview:
Sentiment analysis consists of polarity and subjectivity.
- Polarity has a range between -1 (extremely negative) to 1 (extremely positive).
- Subjectivity has a range between 0 (extremely objective) to 1 (extremely subjectively)


Pres. Trump sentiment overview:


Sentiment overview comparison:
In terms of average, Pres. Obama is slightly less positive and less subjective than Pres. Trump.
Pres. Trump has a higher variance as compared to Pres. Obama.
Based on the distribution of subjectivity, I think that Pres. Obama’s Twitter account is more professional (objective), while Pres. Trump’s account is more personal (subjective).
Pres. Obama top 10 likes:

Here are the links to the tweets:
- https://twitter.com/BarackObama/status/896523232098078720
- https://twitter.com/BarackObama/status/887836712822558720
- https://twitter.com/BarackObama/status/932685522820042754
- https://twitter.com/BarackObama/status/822550300942856193
- https://twitter.com/BarackObama/status/914832655170011137
- https://twitter.com/BarackObama/status/966704319658647553
- https://twitter.com/BarackObama/status/898261944095789056
- https://twitter.com/BarackObama/status/896523304873238528
- https://twitter.com/BarackObama/status/977592827348742146
- https://twitter.com/BarackObama/status/963811333685817346
Here are the themes: Don’t be racist; Respect soldiers; Mass shooting is bad; Young people are our future; Love > hate;
Pres. Trump top 10 likes:

Here are the links to the tweets:
- https://twitter.com/realDonaldTrump/status/929511061954297857
- https://twitter.com/realDonaldTrump/status/796315640307060738
- https://twitter.com/realDonaldTrump/status/881503147168071680
- https://twitter.com/realDonaldTrump/status/795954831718498305
- https://twitter.com/realDonaldTrump/status/948355557022420992
- https://twitter.com/realDonaldTrump/status/823174199036542980
- https://twitter.com/realDonaldTrump/status/815185071317676033
- https://twitter.com/realDonaldTrump/status/914810093874671617
- https://twitter.com/realDonaldTrump/status/947802588174577664
- https://twitter.com/realDonaldTrump/status/741007091947556864
Here are the themes: Kim Jong-un; Respect soldiers; MAGA; We will win;
Pres. Obama top 10 retweets:

Here are the links to the tweets:
- https://twitter.com/BarackObama/status/896523232098078720
- https://twitter.com/BarackObama/status/266031293945503744
- https://twitter.com/BarackObama/status/932685522820042754
- https://twitter.com/BarackObama/status/896523304873238528
- https://twitter.com/BarackObama/status/966704319658647553
- https://twitter.com/BarackObama/status/910330388219916290
- https://twitter.com/BarackObama/status/822550300942856193
- https://twitter.com/BarackObama/status/887836712822558720
- https://twitter.com/BarackObama/status/896523357272911872
- https://twitter.com/BarackObama/status/914832655170011137
Here are the keywords I suggest: Same as top 10 likes;
Pres. Trump top 10 retweets:

Here are the links to the tweets:
- https://twitter.com/realDonaldTrump/status/881503147168071680
- https://twitter.com/realDonaldTrump/status/795954831718498305
- https://twitter.com/realDonaldTrump/status/929511061954297857
- https://twitter.com/realDonaldTrump/status/796315640307060738
- https://twitter.com/realDonaldTrump/status/474134260149157888
- https://twitter.com/realDonaldTrump/status/373743492151136256
- https://twitter.com/realDonaldTrump/status/948355557022420992
- https://twitter.com/realDonaldTrump/status/741007091947556864
- https://twitter.com/realDonaldTrump/status/266038556504494082
- https://twitter.com/realDonaldTrump/status/815185071317676033
Here are the themes: Impeach incompetent president; Electoral college bad for democracy; Hillary delete emails
Pres. Obama top 10 replies:

Here are the links to the tweets:
- https://twitter.com/BarackObama/status/822550300942856193
- https://twitter.com/BarackObama/status/896523232098078720
- https://twitter.com/BarackObama/status/266031293945503744
- https://twitter.com/BarackObama/status/945324527520804866
- https://twitter.com/BarackObama/status/905141484386750469
- https://twitter.com/BarackObama/status/933707825821421568
- https://twitter.com/BarackObama/status/966704319658647553
- https://twitter.com/BarackObama/status/964185606803853314
- https://twitter.com/BarackObama/status/887836712822558720
- https://twitter.com/BarackObama/status/952914779458424832
Here are the themes: We stand behind mass shooting victims;
Pres. Trump top 10 replies:

Here are the links to the tweets:
- https://twitter.com/realDonaldTrump/status/948355557022420992
- https://twitter.com/realDonaldTrump/status/829836231802515457
- https://twitter.com/realDonaldTrump/status/881503147168071680
- https://twitter.com/realDonaldTrump/status/946531657229701120
- https://twitter.com/realDonaldTrump/status/929511061954297857
- https://twitter.com/realDonaldTrump/status/934189999045693441
- https://twitter.com/realDonaldTrump/status/949619270631256064
- https://twitter.com/realDonaldTrump/status/911572182060453893
- https://twitter.com/realDonaldTrump/status/976765417908776963
- https://twitter.com/realDonaldTrump/status/837996746236182529
Here are the themes I suggest: Kim Jong-un; National security; I am awesome;
Pres. Obama top 100 mentions:

Pres. Trump top 10 replies:

Pres. Obama top 100 hashtags:

Pres. Trump top 100 hashtags:

Pres. Obama top 100 keywords:
All the keywords are cleaned. While some of them are not perfect, they are good enough for this project.

Here are their original spellings (original word, cleaned word):
[('your', 'ymy')], [('congress', 'congres')], [("n't #", 'nt')]; [('//wh.gov/live #', 'whgovlive')];
Pres. Trump top 100 keywords:

Here are their original spellings (original word, cleaned word):
[('was', 'wa'), ('wa', 'wa'), ('w/a', 'wa')]; [('via', 'vium')];
Pres. Obama top 100 Noun-phrases (NP):

Here are their original spellings (original word, cleaned word):
[('vp biden', 'vpbiden')]; [("'s plan", 'splan'), ("'s plans", 'splan'), ('’ s plan', 'splan'), ('’ s plans', 'splan')];
Pres. Trump top 100 Noun-phrases (NP):

Here are their original spellings (original word, cleaned word):
[('russia', 'russium')];
Pres. Obama tweet frequency (Day of week VS Year):

Pres. Trump tweet frequency (Day of week VS Year):

Pres. Obama tweet frequency (Day of month VS Year):

Pres. Trump tweet frequency (Day of month VS Year):

Pres. Obama tweet frequency (Hour (GMT) VS Year):

Pres. Trump tweet frequency (Hour (GMT) VS Year):

Final thoughts
Based on the result, I would say that Pres. Obama's account gives me a professional vibe, and I would tend to take his tweets more seriously than Pres. Trump. However, Pres. Trump's account allows me to understand him as an individual better than Pres. Obama.
Since these 2 accounts are so different in terms of vibe (professional vs personal). I don't have a table to summarize the similarities and differences between these 2 accounts.
Published: 2018-04-01 | Updated: 2021-04-02