Issue
I am having an excel file where the "value" column contains different language statements. I want to translate the entire value column into English.
For testing purpose I'm using the below code, but it's throwing some exception
import pandas as pd
from googletrans import Translator
exl_file = 'ipfile1.xlsx'
df = pd.read_excel(exl_file)
print(df)
translator = Translator()
df1 = df['value'].apply(translator.translate, src='es', dest='en').apply(getattr, args=('text',))
print(df1)
Can you please guide how to apply translator on each rows to convert into English?
Solution
You can .apply
the translator to the value
column like this:
df['translated_value'] = df['value'].apply(lambda x: translator.translate(x, dest='en').text)
Answered By - oh_my_lawdy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.