Diego Marino
Diego Marino

Reputation: 79

Applying translate() to a pandas dataframe

I have a pandas dataframe with tweets in portuguese. I want to translate them in a new column of the dataframe using textblob.

df_pt['Traduccion'] = df_pt['text'].apply(TextBlob.translate(from_lang="pt",to='en'))

This is the error I get:

TypeError: translate() missing 1 required positional argument: 'self'

This is a sample of what I have in df_pt['text']:

Acabou de publicar uma foto em Penha Circular, Rio De Janeiro, Brazil

Upvotes: 1

Views: 1915

Answers (1)

Jason
Jason

Reputation: 21

translate() require instantiation before use.

Try this:

df['Traduccion'] = df['text'].apply(lambda x: TextBlob(x).translate(from_lang="pt", to='en')).astype('str')

Upvotes: 2

Related Questions