我正在尝试翻译(从自动检测到英语)这个熊猫数据帧。我不能只是将数据帧插入转换器。我认为它需要转换成JSON,然后翻译成字典,然后移回数据帧。我希望最终将其作为一个新列合并回原始数据帧。我的输出不是我期望的。希望你能帮忙
在
import pandas as pd
from google.cloud import translate_v2 as translate
import os
import json
d = {'compression': ['Ttnft, تارودانت, 111111', 'Sstma, Санкт-Петербург, B-8601 Gzprmbnk, Екатеринбург HUJ852']}
df = pd.DataFrame(data=d)
inputStrings = df['compression'].to_json()
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "Google secure account ID"
translate_client = translate.Client()
result = translate_client.translate(inputStrings, target_language='en')
df2 = pd.DataFrame(data = result, index=[0])
print(df2)
输出:
translatedText detectedSourceLanguage input
0 {"0":"Rsst, 11211, Brooklyn","1":"Ttnft, \u062... en {"0":"Rsst, 11211, Brooklyn","1":"Ttnft, \u062...
目前没有回答
相关问题 更多 >
编程相关推荐