Created
July 4, 2018 19:06
-
-
Save himlohiya/c82d4407fa2921ec7b8d35206576d1b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textblob import TextBlob | |
# compute sentiment scores (polarity) and labels | |
sentiment_scores_tb = [round(TextBlob(article).sentiment.polarity, 3) for article in news_df['clean_text']] | |
sentiment_category_tb = ['positive' if score > 0 | |
else 'negative' if score < 0 | |
else 'neutral' | |
for score in sentiment_scores_tb] | |
# sentiment statistics per news category | |
df = pd.DataFrame([list(news_df['news_category']), sentiment_scores_tb, sentiment_category_tb]).T | |
df.columns = ['news_category', 'sentiment_score', 'sentiment_category'] | |
df['sentiment_score'] = df.sentiment_score.astype('float') | |
df.groupby(by=['news_category']).describe() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment