I am using some Trump tweets, some recent some older. Documentation for Textblob is available here, and on Github
from textblob import TextBlob
with open('cleaned_tweets.txt') as ip_file:
text = ip_file.readlines()
for tweet in text:
print('tweet: ' + tweet)
analysis = TextBlob(tweet)
if analysis.sentiment.polarity > 0:
elif analysis.sentiment.polarity == 0:
print('polarity: ' + str(analysis.sentiment.polarity))
print('subjectivity: ' + str(analysis.subjectivity))
tweet: My daughter Ivanka has been treated so unfairly by Nordstrom. She is a great person -- always pushing me to do the right thing! Terrible!
Comments: The polarity is slightly less than zero so overall it is negative. This seems reasonable as part of the tweet is very positive however the overall message is negative against Nodstrom. A subjectivity score close to 1.0 suggests a subjective message again this seems fair, the tweet is thin on facts and is mostly Trump's opinions.
tweet: 'Majority in Leading EU Nations Support Trump-Style Travel Ban'
Comments: Again I think this is a good result. The tweet is neutral and factual i.e. objective rather than subjective. Note that when I say factual I am not necessarily agreeing with the data Trump is quoting.
tweet: It is a disgrace that my full Cabinet is still not in place, the longest such delay in the history of our country. Obstruction by Democrats!
Comments: Here the sentiment is incorrectly marked as positive.
tweet: I love you North Carolina- thank you for your amazing support! Get out and http://VOTE.GOP tomorrow!
Comments: Good result.
Overall the package produced good results but sometimes it was incorrect. But it does get an A+ for ease of use.
This blog includes:
Scripts mainly in Python with a few in R covering NLP, Pandas, Matplotlib and others. See the home page for links to some of the scripts. Also includes some explanations of basic data science terminology.