按情感上色
我们希望在 Twitter 分析中能区分不同地点。其中一个区分因素是各地对国情咨文演讲的反应。为此,我们将使用第 2 章中介绍的情感分析,评估全国不同地区对这次演讲的接受程度。
数据集 tweets_sotu 已为您加载,同时还有 lon、lat 和 Basemap 地图 m。SentimentIntensityAnalyzer 已在您的工作区以 sid 实例化。
本练习是课程的一部分
在 Python 中分析社交媒体数据
练习说明
- 计算情感分数并保存。
- 绘制这些点,将颜色参数设为
sentiment_score,并将颜色映射设为 'coolwarm'。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Generate sentiment scores
sentiment_scores = ____[____].apply(____)
# Isolate the compound element
sentiment_scores = [x['compound'] for x in sentiment_scores]
# Draw the points
____.____(____, ____, ____ = True,
c = ____,
____ = 'coolwarm', alpha = 0.7)
# Show the plot
plt.show()