I'm trying to translate (from auto detect to english) each of these rows in a pandas Dataframe. I can't just plug in the dataframe into translator. I think it needs to be converted to JSON and then translated into a dictionary, and then moved back into a dataframe.
The dataframe comes out looking weird and I'm really confused
Is there a better way to do this?
Here's my code:
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)
Ultimately I'd like to append the new translation back to the original dataframe. I'm not sure whether it's better to replace the existing column or add a new one. Hope you can help! thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…