Excel sheet translation using python

Viewed 4815

I have an excel sheet filled with English text, so now I wanted to convert each text to other languages (example:- french) and insert in the next column of the excel sheet using python.

So how to approach this?

I'm currently going through pandas of python.

1 Answers

This should work. Make sure you pip install googletrans-temp

import pandas as pd
from googletrans import Translator 

# read from an excel file
df = pd.read_excel('/Users/andrewgreatorex/Downloads/test_spreadsheet.xlsx')

# translate a column to French, and add back into the DataFrame
translator = Translator()         
df['French'] = df['text'].apply(translator.translate,src='en',dest='fr').apply(getattr, args=('text',))

# output new excel file
df.to_excel('name_of_your_output_file.xlsx')
Related