3

i want to translate column of my dataframe from french to english.

 from googletrans import Translator 
 translator = Translator()         
 df = pd.DataFrame({'French':['ma voiture','Il fait beau aujourdhui']})
 df['English'] = df['French'].apply(translator.translate,src='fr',dest='en').apply(getattr, args=('text',))

I did these lines but i found an error.. How can i solve it please.?

4
  • Note that in line 1 you miss a comma after aujourd' and a quote before hui.Moreover, what is the definition of translator? Commented Apr 22, 2019 at 14:14
  • yepp .. from googletrans import Translator translator = Translator() Commented Apr 22, 2019 at 14:15
  • @sentence do you see what i mean? Commented Apr 22, 2019 at 14:29
  • Unfortunately I do not use that package. As suggested by @chitown88, maybe you should try with other packages. Commented Apr 22, 2019 at 17:57

2 Answers 2

0

Well I was having an issue with googletrans. But then tried the solution here that suggests to do:

pip install googletrans-temp

And your code seemed to work just fine:

Output:

print (df)
                    French                         English
0               ma voiture                          my car
1  Il fait beau aujourdhui  Such a beautiful weather today
Sign up to request clarification or add additional context in comments.

10 Comments

i have always the same problem of ** JSONDecodeError: Expecting value: line 1 column 1 (char 0)**
same error do you see how to solve it .. I did all what you recommand
you get the same error with just the rows in the dataframe?
yep with the same dataframe and the same rows
not really sure. May just have to find another library or package. I'm not too familiar with other ones. You might just have to search around and see.
|
0

Google Translate has limits on volume translated. EasyNMT is a scalable solution.

from easynmt import EasyNMT
model = EasyNMT("opus-mt")

df["English"] = df.apply(lambda row: model.translate(row["French"], target_lang="en"), axis=1)

2 Comments

please specify a complete example. The above does not seem to work with EasyNMT, but gives OSError: Helsinki-NLP/opus-mt-lt-en is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models' If this is a private repository, make sure to pass a token having permission to this repo either by logging in with huggingface-cli login` or by passing `token=<your_token>``
Can you please share a data snapshot and the relevant code snippet you are running (helps understand the error)? I believe we are trying to translate from Lithuanian to English here. This is the relevant model on HuggingFace: huggingface.co/Helsinki-NLP/opus-mt-tc-big-lt-en

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.