Created
June 28, 2020 22:12
-
-
Save pablodz/3b965564bcfe26cc163582871f539d8a to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 0, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
], | |
"source": [ | |
"def get_polarity():\n", | |
" for i in range(len(df)):#len(df)\n", | |
" try:\n", | |
" temp=df['RelatoFixedTranslated'][i] \n", | |
" # translation= translate_client.translate(temp,target_language='en',source_language='es') # Already translated\n", | |
" # translation=translation['translatedText'] # Already translated\n", | |
" p=sid.polarity_scores(str(temp))['compound']\n", | |
" neg=sid.polarity_scores(str(temp))['neg']\n", | |
" neu=sid.polarity_scores(str(temp))['neu']\n", | |
" pos=sid.polarity_scores(str(temp))['pos']\n", | |
" df.loc[i,'polarity']=p\n", | |
" df.loc[i,'neg']=neg\n", | |
" df.loc[i,'neu']=neu\n", | |
" df.loc[i,'pos']=pos\n", | |
" #df.loc[i,'translated']=str(translation) # Already translated\n", | |
" print(i,end=' - ')\n", | |
" #sleep(0.1+random.random()/2) # Already translated\n", | |
" except Exception as e:\n", | |
" print('Error {}:{}'.format(i,e))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (system-wide)", | |
"language": "python", | |
"metadata": { | |
"cocalc": { | |
"description": "Python 3 programming language", | |
"priority": 100, | |
"url": "https://www.python.org/" | |
} | |
}, | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment