运行以下代码时出现jsondecode错误。我正在尝试翻译我在数据框df中的文本。如果未传递任何参数,call_api将起作用。
def call_api(s,t):
ts_url = 'some_url'
SOURCE_LANGUAGE = s
Target_Language = 'en'
original_Review = t
PARAMS = {"user":"username", "password":"password",
"source": SOURCE_LANGUAGE,
"target": Target_Language,
"domain": "generic",
"text": original_Review}
r = requests.get(url = ts_url, params = PARAMS)
p = r.json()
print(type(p['translation']))
return p['translation']
df['Translated Review Title'] = df.apply(lambda row: call_api(row['source_language'], row['review_title']), axis = 1)
我想翻译并保存翻译后的文本到新的dataframe列中。