1

I have a dataframe with several columns including a text column, when I use the code from here which is:

import pandas as pd
from googletrans import Translator

translator = Translator(service_urls=['translate.google.com',])

df["translate_result"] = df["to_translate"].apply(lambda x: translator.translate(x, src= "en", dest = "fr").text)

I get the error message :

AttributeError: 'NoneType' object has no attribute 'group'

I tried to update the translator function with service urls but it seems not the problem. What could be the issue here? thank you.

3
  • so i am currently trying another solution from here: pythonrepo.com/repo/… using #deep-translator-1.5.0 Commented Aug 8, 2021 at 19:44
  • 1
    have you actually checked if all elements of your data column have a .text attribute that is not None? Commented Aug 8, 2021 at 23:23
  • yup, the same error appears when testing the solution from @Ricco D Commented Aug 9, 2021 at 8:28

1 Answer 1

2

I got the same error when I used googletrans v3 then I found an open github issue for this error. The suggested fix is to use version googletrans-4.0.0rc1-py3.9.egg-info.

pip install 'googletrans==4.0.0rc1'

translate.py:

from googletrans import Translator
import pandas as pd

translator = Translator()

df = pd.DataFrame({'Spanish':['piso','cama']})
df['English'] = df['Spanish'].apply(translator.translate, src='es', dest='en').apply(getattr, args=('text',))
print(df)

I ran the code from the link you provided in the question and got the expected results.

Test done: enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

the solution and code provided by you produces an error message: AttributeError: 'NoneType' object has no attribute 'group'. any ideas why? thanks.
After testing in python 3.9 .py env the code you provides works. The comment above comes from using the jupyter notebook
Another git issue suggest to use googletrans==3.1.0a0. You can also try this one.
where can I find the rate limit of words to translate using this package? thank you.
@brygid it might be better to create a new post for your question regarding the limit of words since it is not related to the original question. Creating a new question will also open an opportunity for the community to contribute :)

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.