How to calculate a simple sentiment score for a text?

The vader library provides a straightforward sentiment score. It is based on a word list, so it is not super accurate and does not catch any nuances. But it is fast and sufficient for a quick scan.

Installation

pip install vaderSentiment

Usage

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

s  = SentimentIntensityAnalyzer()

text_a = "\ntoday is a great day to code!"
text_b = "\nsyntax errors really suck"

print(text_a)
print(s.polarity_scores(text_a))

print(text_b)
print(s.polarity_scores(text_b))

The sentiment includes a positive, negative and neutral score, which add up to 1.0.