Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created August 15, 2020 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aniruddha27/7d1a63ddaed056009d6f7ad88a9714fb to your computer and use it in GitHub Desktop.
Save aniruddha27/7d1a63ddaed056009d6f7ad88a9714fb to your computer and use it in GitHub Desktop.
# Sentiment analysis using Textblob
def sentiment(tweet):
analysis = TextBlob(tweet)
if analysis.sentiment.polarity > 0:
return 1
elif analysis.sentiment.polarity == 0:
return 0
else:
return -1
df_tweet['Sentiment'] = df_tweet['Clean_Tweet'].apply(sentiment)
df_tweet.head(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment