开始使用免费开始使用

获取请求的情感倾向

在成功为市政道路主管翻译了 Get It Done 案件后,他又提出了一个需求。他非常想了解市民对其部门工作的看法。她认为可以通过对 Get It Done 请求进行情感分析来回答这个问题。她已经将 CSV 加载到变量 dumping_df 中,并筛选为以下列:

Get It Done requests in many languages

在本练习中,您将帮助 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()
编辑并运行代码