依情緒著色
我們想在 Twitter 分析中區分不同地點。各地之間的一個差異,是他們對 State of the Union 演說的反應。為了達到這個目的,我們會使用第 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()