Skip to content

Instantly share code, notes, and snippets.

@idcesares
Created April 26, 2021 22:51
Show Gist options
  • Select an option

  • Save idcesares/4b789a64e91a43a96d4f8a2f999b0e2e to your computer and use it in GitHub Desktop.

Select an option

Save idcesares/4b789a64e91a43a96d4f8a2f999b0e2e to your computer and use it in GitHub Desktop.
Simple Sentiment Analysis using TextBlob Python Library. Only available in english.
from textblob import TextBlob
def sentiment(text):
base_text = TextBlob(text)
sentiment_score = base_text.sentiment.polarity
if sentiment_score < 0:
return 'Negative'
elif sentiment_score == 0:
return 'Neutral'
return 'Positive'
result = sentiment("I'm very happy")
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment