{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def analize_sentiment(tweet):\n", | |
" analysis = TextBlob(tweet)\n", | |
" if analysis.sentiment.polarity > 0:\n", | |
" return 1\n", | |
" elif analysis.sentiment.polarity == 0:\n", | |
" return 0\n", | |
" else:\n", | |
" return -1\n", | |
"data['sentiment'] = np.array([ analize_sentiment(tweet) for tweet in data['Tweets_Cln']])\n", | |
"display(data.head(2))\n", | |
"\n", | |
"positive=data.loc[data.sentiment==1,'Tweets'].count()\n", | |
"negative=data.loc[data.sentiment==-1,'Tweets'].count()\n", | |
"neutral=data.loc[data.sentiment==0,'Tweets'].count()\n", | |
"\n", | |
"#Let's plot\n", | |
"labels='Postive', 'Negative', 'Neutral'\n", | |
"sizes=[positive, negative, neutral]\n", | |
"explode=(0, 0.1, 0)\n", | |
"fig1, ax1 = plt.subplots()\n", | |
"ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',\n", | |
" shadow=True, startangle=0)\n", | |
"ax1.axis('equal') \n", | |
"plt.show()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"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.7.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment