3

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 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Andy!!! But sometimes it works fine and sometimes I'm getting "JSONDecodeError: Expecting value" can I know the reason for it. If I get this error then it is not working at all.
df['French'] = df['text'].apply(translator.translate,src='en',dest='fr').apply(getattr, args=('text',))..... If once it comes then the code doesn't run at all and throws same error
Came to know that this error is because of character limit that Google translate has 15k. How to overcome this? Should I change the code?
Try using a different translation package, pypi.org/project/translate looks like it might do the trick
Yes it works!! But even this has a limit for translation same as Google translate API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.