简体   繁体   中英

Translate a Pandas df using googletrans, AttributeError error

I am trying to translate words from a Pandas dataframe column and get error in googletrans.Translator() class. It works normal with single words or phrases. Can it be environmental issue?

Any help or suggestions much appreciated

import pandas as pd 
from googletrans import Translator

translator = Translator()

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

Output:

AttributeError: 'Translator' object has no attribute 'raise_Exception'

Hi this error occured because there is an exception occurred in the runtime. To see the error insert this below code

python translator.raise_Exception = True If you get the error as below

Exception: Unexpected status code "429" from ['translate.google.com']

which means Too many requests. Hope you would not get this error. If so you have to upgrade you account. To avoid the error please refer this answer

Source 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM