Skip to content

Instantly share code, notes, and snippets.

@glickmac
Last active December 17, 2019 20:20
Show Gist options
  • Save glickmac/d589847d14ebe1f2e3cf4c982b900998 to your computer and use it in GitHub Desktop.
Save glickmac/d589847d14ebe1f2e3cf4c982b900998 to your computer and use it in GitHub Desktop.
def Chapter_Sentiment(Chapter_Text):
def Average(lst):
return float(sum(lst)) / len(lst)
sid = SentimentIntensityAnalyzer()
sentences = Chapter_Text.split('.')
sentiment_scores = []
for item in sentences:
sentiment = sid.polarity_scores(item)
sentiment_value = sentiment['compound']
sentiment_scores.append(sentiment_value)
return(Average(sentiment_scores))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment