Skip to content

Instantly share code, notes, and snippets.

@Rteenajain
Created May 8, 2020 05:42
Show Gist options
  • Save Rteenajain/e3f04c172ecbe3717900659c23de4c45 to your computer and use it in GitHub Desktop.
Save Rteenajain/e3f04c172ecbe3717900659c23de4c45 to your computer and use it in GitHub Desktop.
Language Translation using textblob python library
from textblob import TextBlob
import pandas as pd
import time
#Function to translate to english
def translate(x):
try:
blob=TextBlob(x)
return (str(blob.translate(to = 'en')))
except:
return None
to_translate=pd.read_excel('Filename path and name here')
to_translate['description']=to_translate.description.astype(str) ##converting column to string where translation is required
strt_time=time.time()
to_translate['Converted_Eng_Sentence'] = to_translate['description'].apply(lambda x: translate(x)) #Translation happening
end_time=time.time()
print(end_time-strt_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment