Search code examples
pythonpandasnltktranslate

trying to convert a whole column from Spanish to English, with the translate module


I'm trying to convert a column containing Spanish tweets (removi stop words, tokenize and stemming process were done) to English with the translate module, but it doesn't work for me.

This is the code:

from translate import Translator
translator= Translator(to_lang="en")
translation = translator.translate(tweetsCleaned['cleanedTweet'])
print(translation)

This is the result that i get:

0       andeportes   preocupados   salud   ex   camp...
1       strellaonline   spanama   realidad   crítica...
2       sobresaliente   desempeño   bac   credimatic...
3       sdemontero   migrantes   venezolanos   ciuda...
4       tvcanal8   envideo   presidente   venezuela ...
5       tvcanal8   envideo   presidente   venezuela ...
6       echuguinoscom   bienvenidos   casa   plan   ...
7       tvcanal8   envideo   presidente   venezuela ...
8       cuanto   suele   durar   orgasmo   tortuga  ...
9       edardito   panamá   si   70   juan   diegos ...
10      enanpanama   presentan   programa   pescador...
11      ucusahernandez   importante   gobernador   e...
12      tvcanal8   envideo   presidente   venezuela ...

Text still in spanish.


Solution

  • If you are using translate library 'https://pypi.org/project/translate/ ' and not googletrans then try this (i am not sure about 'es' if it represents Spanish, but you can change it)

    translator= Translator(from_lang = 'es',to_lang='en')
    tweetsCleaned['cleanedTweet'] = tweetsCleaned['cleanedTweet'].apply(lambda x: translator.translate(x))