Reputation: 73
I am trying to translate a text column using python which contain different text of different languages . nothing fancy with my code yet .
import pandas as pd
df = pd.read_excel('D:/path', head=None)
I used the following code :
from googletrans import Translator
translator = Translator()
df['Text to English'] = df['Text'].apply(translator.translate, src='id', dest='en')
but it gave me an error :
AttributeError: 'NoneType' object has no attribute 'group'
I search more for any other code and I came up with :
from textblob import TextBlob
df['Text to English'] = df['Text'].str.encode('ascii', 'ignore').apply(lambda x: TextBlob(x.strip()).translate(to='en'))
but it gave me an error of : TypeError: cannot use a string pattern on a bytes-like object
is there any solution for this ?? and thanks in advance
Upvotes: 2
Views: 2797