python google translate csv code example

Example: python google translate csv

import pandas as pd 
from google_trans_new import google_translator  
translator = google_translator()  
translate_text = translator.translate('Hola mundo!', lang_src='es', lang_tgt='en')  

df = pd.read_csv('./my_file.csv')
translations = []
unique_elements = df['text'].unique()
countr = 0
for element in unique_elements:
    countr += 1
    translations.append(f'{str(countr)}|{translator.translate(element, lang_src="es", lang_tgt="en")}')  

ostream = open ('./my_file_en.csv', 'w', encoding='utf-8')
ostream.write('\n'.join(translations))
ostream.close()