I am running a Sentiment Analysis from Twitter. My code is running without any issue but there is one thing that got my attention. When I run my script for "Stack OverFlow", it shows only 15 comments in total. I don't think this is possible(only 15 comments related to Stack OverFlow in Twitter). I am not sure if I have done something wrong in the logic.
import tweepy
from textblob import TextBlob
import pandas as pd
from plotly import __version__
import cufflinks as cf
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
init_notebook_mode(connected=True)
cf.go_offline()
consumer_key = ''
consumer_key_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
public_tweets = api.search('Stack OverFlow')
pos, neg, neu = 0, 0, 0
for tweet in public_tweets:
print(tweet.text)
analysis = TextBlob(tweet.text)
print(analysis.sentiment)
if analysis.sentiment[0]>0:
pos+=1
elif analysis.sentiment[0]<0:
neg+=1
else:
neu+=1
print("Positive: {}\nNegative: {}\nNeutral: {}".format(pos,neg,neu))
values=[pos,neg,neu]
Labels=["Positive","Negative","Neutral"]
df=pd.DataFrame({'Label':['Positive','Negative','Neutral'],'Values':[pos,neg,neu]})
df.iplot(kind='bar',x='Label',y='Values',title='Sentiment Analysis: Stack OverFlow')
****My Results: Sentiment(polarity=0.125, subjectivity=0.8) Positive: 7 Negative: 1 Neutral: 7****