Created
May 8, 2020 05:42
-
-
Save Rteenajain/e3f04c172ecbe3717900659c23de4c45 to your computer and use it in GitHub Desktop.
Language Translation using textblob python library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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