Bắt đầu ngayBắt đầu miễn phí

Coloring by sentiment

We want to be able to differentiate by place with our Twitter analysis. One distinguishing factor between places is how the State of the Union speech was received. For this purpose, we'll use the sentiment analysis we covered in Chapter 2 to evaluate how the speech was received in different parts of the country.

The tweets_sotu dataset has been loaded for you, as well as lon, lat, and the Basemap map m. SentimentIntensityAnalyzer is instantiated as sid in your workspace.

Bài tập này là một phần của khóa học

Analyzing Social Media Data in Python

Xem khóa học

Hướng dẫn bài tập

  • Calculate the sentiment scores and store them.
  • Draw the points, setting the color argument to sentiment_score and the colormap to 'coolwarm'.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# 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()
Chỉnh sửa và Chạy Mã