取得請求的情感傾向
在你成功為市容維護處的主管翻譯 Get It Done 案件後,他又提出一個需求。他很想了解市民對該單位工作的感受。她相信可以透過對 Get It Done 請求做情感分析來回答這個問題。她已經把 CSV 載入到變數 dumping_df,並篩選成下列欄位:

在這個練習中,你將協助 Sam 更了解提交 Get It Done 案件的市民情緒,以及他們與市府互動時,整體上是抱持正向還是負向的心情。
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 偵測每一列
'public_description'的情感傾向。 - 將結果儲存在
'sentiment'欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
for index, row in dumping_df.iterrows():
# Get the translated_desc into a variable
description = dumping_df.loc[index, 'public_description']
if description != '':
# Get the detect_sentiment response
response = comprehend.____(
____=description,
____='en')
# Get the sentiment key value into sentiment column
dumping_df.loc[index, 'sentiment'] = response['____']
# Preview the dataframe
dumping_df.head()