1

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

3
  • I also realized that the type of df_pt['text'] is incorrect but I dont know how to take care of it either Commented Dec 28, 2018 at 1:09
  • 1
    Provide df_pt['text'] sample. Commented Dec 28, 2018 at 1:11
  • If I do type, I get pandas.core.series.Series Commented Dec 28, 2018 at 1:23

1 Answer 1

2

translate() require instantiation before use.

Try this:

df['Traduccion'] = df['text'].apply(lambda x: TextBlob(x).translate(from_lang="pt", to='en')).astype('str')
Sign up to request clarification or add additional context in comments.

2 Comments

returned this: HTTPError: Service Unavailable. Maybe the error is that some tweets contain urls and emojis?
In that case, I suggest you write another function to handle exceptions instead.

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.