リクエストの感情を取得する
Streets Director 向けに Get It Done の案件をうまく翻訳できたところで、彼からもう一つ依頼がありました。市民が彼の部門の仕事をどう感じているのかを理解したいというのです。彼は、Get It Done のリクエストを感情分析することでその問いに答えられると考えています。彼女はすでに CSV を dumping_df 変数に読み込み、次の列に絞り込み済みです。

この演習では、Get It Done の案件を投稿した人たちの声のムードをよりよく理解し、市とのやり取りにポジティブな気分で臨んでいるのか、それともネガティブなのかを Sam が把握できるよう支援します。
この演習はコースの一部です
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()