I have pandas dataframe column in Polish language and want to translate into English Language but I got error. Code below:
from googletrans import Translator
translator = Translator()
df['text_en'] = df2['text_pl'].apply(translator.translate, src='pl', dest='en')
Error Below:
63
64 # this will be the same as python code after stripping out a reserved word 'var'
---> 65 code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
66 # unescape special ascii characters such like a \x3d(=)
67 if PY3: # pragma: no cover
AttributeError: 'NoneType' object has no attribute 'group'
I don't know if you've solved your issue but I experienced the same thing. I discovered the module
google_trans_new
. You should try it:For the translation part:
which return:
For detection:
which gives
In your case, it would maybe work this way:
to detect the language (if your not sure all is in english or polish).
And in a similar way to translate. (See example above). I did this way:
and then merged it with the original dataframe. (Reason of choice: 40 languages and some "weird" text I wasn't sure would be translatable), but you may not need to do it that way.