0

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****

Verbamore
  • 189
  • 2
  • 2
  • 10
  • Have you tried looking for StackOverflow instead? – jonyfries Feb 22 '19 at 21:24
  • @jonyfries just to clarify my point. I am using StackOverflow as an example. I can guarantee you that whatever target I choose, the number of comments is low. I think. I might have something wrong in the logic. My expected result is: sentiment analysis of all of the comments that Twitter's database has related to the targeted word. – Verbamore Feb 24 '19 at 23:18

0 Answers0