翻译 Get It Done 请求
Get It Done 的请求描述中经常混有多种语言。这对许多城市团队来说是个难题。为了审核这些请求,很多团队需要配备翻译,或者指望有人恰好会相应的语言。
市政道路部门主管请 Sam 提供帮助。他希望她在每天结束时运行一个作业,把 Get It Done 请求翻译出来。
Sam 决定使用 AWS 的翻译服务来处理这些请求。她已经把 CSV 加载到变量 dumping_df 中,并筛选为以下列:

请帮助 Sam 使用 AWS 翻译服务将这些请求翻译成西班牙语!
本练习是课程的一部分
Python 中的 AWS Boto 入门
练习说明
- 对于 DataFrame 中的每一行,将其翻译成英语。
- 将原始语言存入
original_lang列。 - 将新的译文存入
translated_desc列。
交互式实操练习
通过完成这段示例代码来试试这个练习。
for index, row in dumping_df.iterrows():
# Get the public_description into a variable
description = dumping_df.loc[index, 'public_description']
if description != '':
# Translate the public description
resp = translate.____(
____=description,
____='auto', ____='en')
# Store original language in original_lang column
dumping_df.loc[index, 'original_lang'] = resp['____']
# Store the translation in the translated_desc column
dumping_df.loc[index, 'translated_desc'] = resp['____']
# Preview the resulting DataFrame
dumping_df = dumping_df[['service_request_id', 'original_lang', 'translated_desc']]
dumping_df.head()