0

I am trying to convert a column to english , but i get AttributeError: 'NoneType' object has no attribute 'group'.

Here is my code:

from googletrans import Translator
translator = Translator()
df['Name'] = df['Name'].apply(translator.translate, dest='en')

Name

สวัสดีจีน

日本国)

日本の会社

1 Answers1

0

It appears that some of the newer versions of this library have known issues. Please run this code below to install a working version and restart your kernel:

pip install googletrans==3.1.0a0

#this also may work for a working newer version:
pip install googletrans==4.0.0-rc1

Then, run the below code to confirm it is working. This solved for me. CREDIT to this answer (Moritz's Answer):

import pandas as pd
from googletrans import Translator
df = pd.DataFrame({'Name': {0: 'สวัสดีจีน', 1: '日本国)', 2: '日本の会社'}})
translator = Translator()
df['Name2'] = df['Name'].apply(lambda x: translator.translate(x, dest='en').text)
df
Out[1]: 
        Name             Name2
0      สวัสดีจีน       hello china
1       日本国)            Japan)
2      日本の会社  Japanese company
David Erickson
  • 16,433
  • 2
  • 19
  • 35
  • Getting the error: try: ---> 62 # this will be the same as python code after stripping out a reserved word 'var' 63 code = self.RE_TKK.search(r.text).group(1).replace('var ', '') 64 # unescape special ascii characters such like a \x3d(=) AttributeError: 'NoneType' object has no attribute 'group' – Thedatageek Jun 25 '21 at 03:42
  • @Thedatageek the foreign (foreign to me) characters might be causing an issue in my Answer. Try the code itself on your data and remember to restart your kernel after isntalling. Also, try `pip install googletrans==4.0.0-rc1` instead of `pip install googletrans==3.1.0a0`. – David Erickson Jun 25 '21 at 03:44
  • getting : AttributeError: 'Translator' object has no attribute 'raise_Exception'. – Thedatageek Jun 25 '21 at 03:59