JSONDecodeError:('期望值:第1行第1列(字符0)','发生在索引0')

时间:2019-09-11 16:16:14

标签: python-3.x pandas dataframe

运行以下代码时出现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列中。

0 个答案:

没有答案