Translate a column with English and Dutch text to only English using GoogleTrans

171 Views Asked by At

I have a data frame with tweets and I want to translate it to only English. The problem is that the source column has both English and Dutch tweets. I used the following code to try to translate this column:

from googletrans import Translator
translator = Translator()

df_posts['text_en'] = df_posts['text'].apply(lambda x: translator.translate(x, dest='en').text)

I tried some other code from stack as well, but nothing worked. I did update the translator package, so I don't have the common NoneType error anymore. The error I get looks like this:

error that needs to be solved

The source data in the "text" column from the df_posts data frame looks like this (note that this part only shows the English text that doesn't need to be translated):

data that needs translating

0

There are 0 best solutions below