I am trying the below function.
I want to translate the data in 'Text' from the language it's in, which can be determined through
df['Language'] = df.Text.apply(lambda x: TextBlob(str(x)).detect_language())
Into Spanish, which can be done with:
.translate(from_lang='en', to= 'es')
I have tried the below, but I'm not sure how to nest the two function into a single statement?
df['Translated'] = df.Text.apply(lambda x: TextBlob(str(x)).translate(from_lang= df.Text.apply(lambda x: TextBlob(str(x))), to ='en'))
The input dataframe is just a single column with text statements, like:
Text
"I love this game, I think its great"
"really buggy, not a good experience, do not buy"
"not too bad, not too good"
Can anyone help?
您可以使用 DataFrame.apply 而不是使用 Series.apply:
df['Translated'] = df.apply(lambda x: TextBlob(str(x.Text)).translate(from_lang=x.Language, to='en'), axis=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.