Obama VS Trump

I do not own this photo. Here is the link: https://i.ytimg.com/vi/JTCckccilds/maxresdefault.jpg

Introduction:

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:

  1. Chatbots
  2. LawTech to automated contract review
  3. 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:

  1. For the format of this article, I will always present the numbers and figures from Pres. Obama, then Pres. Trump.
  2. I am unable to collect all their tweets because I am unsure of which tweets are missing.

Here is the workflow for this data science project:

Data mining/collection => Data wrangling/cleansing => Data science (analytics, NLP) and visualization

Here’s how I split my efforts over 3 weekends to complete this case study. Data mining (45%), data wrangling (45%) and actual data science (10%). You can refer to this data wrangling file to see how I cleaned the data and the problem I faced when filling up the missing tweets.

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. (See data wrangling file)

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:

It is obvious that Pres. Trump tweet more than Pres. Obama

Pres. Obama metrics overview:

Metrics overview refers to replies, retweets and likes Statistics

Obama’s metrics overview, table form

Pres. Trump metrics overview:

Trump’s metrics overview, table form

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.

  1. Polarity has a range between -1 (extremely negative) to 1 (extremely positive).
  2. Subjectivity has a range between 0 (extremely objective) to 1 (extremely subjectively)
Obama sentiment overview, table form

Pres. Trump sentiment overview:

Trump sentiment overview, table form

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 keywords I suggest: 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:

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 keywords I suggest: Kim Jong-un; Respect soldiers; MAGA; We will win;

Pres. Obama top 10 retweets:

Here are the links:

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:

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 keywords I suggest: Impeach incompetent president; Obama sucks; Electoral college bad for democracy; Hillary delete email

Pres. Obama top 10 replies:

Here are the links:

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 keywords I suggest: We stand behind mass shooting victims;

Pres. Trump top 10 replies:

Here are the links:

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 keywords I suggest: Kim Jong-un; National security; I am awesome;

Pres. Obama top 100 mentions:

Pres. Trump top 100 mentions:

Pres. Obama top 100 hashtags:

Pres. Trump top 100 hashtags:

Pres. Obama top 100 keywords:

All the keywords are cleaned. They have been singularized and lemmatized. While some of the cleaned words 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 spelling (original word, cleaned word):

[('was', 'wa'), ('wa', 'wa'), ('w/a', 'wa')]; [('via', 'vium')];

Pres. Obama top 100 Noun-phrases (NP):

Here are their original spelling (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 spelling (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):


Hit the like button if you like this article! You will help others find it.

Feel free to reach out to me via Linkedin.

I love getting questions or suggestions, so comment away!

Like what you read? Give Shawn Ng a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.