{ "metadata": { "name": "", "signature": "sha256:ecb3149e07c9f2bc76940c175d8a2f133b5f847662839241ab0e52226268d291" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " | contributors | \n", "coordinates | \n", "created_at | \n", "entities | \n", "extended_entities | \n", "favorite_count | \n", "favorited | \n", "filter_level | \n", "geo | \n", "id | \n", "... | \n", "place | \n", "possibly_sensitive | \n", "retweet_count | \n", "retweeted | \n", "retweeted_status | \n", "source | \n", "text | \n", "timestamp_ms | \n", "truncated | \n", "user | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "NaN | \n", "None | \n", "2015-03-09 21:01:01 | \n", "{'trends': [], 'urls': [{'expanded_url': 'http... | \n", "NaN | \n", "0 | \n", "0 | \n", "low | \n", "None | \n", "5.750386e+17 | \n", "... | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "NaN | \n", "<a href=\"http://ifttt.com\" rel=\"nofollow\">IFTT... | \n", "'Gold On My MacBook' is the perfect rap song f... | \n", "1.425935e+12 | \n", "0 | \n", "{'profile_link_color': '009999', 'contributors... | \n", "
1 | \n", "NaN | \n", "None | \n", "2015-03-09 21:08:06 | \n", "{'urls': [], 'symbols': [], 'media': [{'indice... | \n", "{'media': [{'indices': [125, 140], 'url': 'htt... | \n", "0 | \n", "0 | \n", "low | \n", "None | \n", "5.750404e+17 | \n", "... | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "{'extended_entities': {'media': [{'id_str': '5... | \n", "<a href=\"http://twitter.com/download/android\" ... | \n", "RT @MisterC00l: Noyer son Apple Watch en or \u00e0 ... | \n", "1.425935e+12 | \n", "0 | \n", "{'profile_link_color': '0084B4', 'contributors... | \n", "
2 | \n", "NaN | \n", "None | \n", "2015-03-09 21:21:47 | \n", "{'urls': [{'expanded_url': 'http://phon.es/ylj... | \n", "{'media': [{'indices': [104, 126], 'url': 'htt... | \n", "0 | \n", "0 | \n", "low | \n", "None | \n", "5.750438e+17 | \n", "... | \n", "None | \n", "0 | \n", "0 | \n", "0 | \n", "{'extended_entities': {'media': [{'id_str': '5... | \n", "<a href=\"http://twitter.com/download/android\" ... | \n", "RT @androidcentral: Apple's new MacBook cable ... | \n", "1.425936e+12 | \n", "0 | \n", "{'profile_link_color': '0084B4', 'contributors... | \n", "
3 rows \u00d7 28 columns
\n", "\n", " | text | \n", "
---|---|
0 | \n", "127 | \n", "
1 | \n", "573 | \n", "
2 | \n", "545 | \n", "
3 | \n", "556 | \n", "
4 | \n", "495 | \n", "
5 | \n", "444 | \n", "
6 | \n", "471 | \n", "
7 | \n", "492 | \n", "
8 | \n", "324 | \n", "
19 | \n", "199 | \n", "
20 | \n", "386 | \n", "
21 | \n", "397 | \n", "
22 | \n", "414 | \n", "
23 | \n", "395 | \n", "
24 | \n", "401 | \n", "
25 | \n", "355 | \n", "
26 | \n", "286 | \n", "
27 | \n", "387 | \n", "
28 | \n", "385 | \n", "
29 | \n", "363 | \n", "
30 | \n", "455 | \n", "
31 | \n", "397 | \n", "
32 | \n", "417 | \n", "
33 | \n", "420 | \n", "
34 | \n", "301 | \n", "
\n", " | contributors_enabled | \n", "created_at | \n", "default_profile | \n", "default_profile_image | \n", "description | \n", "favourites_count | \n", "follow_request_sent | \n", "followers_count | \n", "following | \n", "friends_count | \n", "... | \n", "profile_sidebar_fill_color | \n", "profile_text_color | \n", "profile_use_background_image | \n", "protected | \n", "screen_name | \n", "statuses_count | \n", "time_zone | \n", "url | \n", "utc_offset | \n", "verified | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
created_at | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
2015-03-09 21:00:45 | \n", "False | \n", "Thu Jun 04 20:59:45 +0000 2009 | \n", "True | \n", "False | \n", "Realzalea bihotzez, software librea filosofiaz... | \n", "94 | \n", "None | \n", "100 | \n", "None | \n", "81 | \n", "... | \n", "DDEEF6 | \n", "333333 | \n", "True | \n", "False | \n", "kristiansanz | \n", "2619 | \n", "Madrid | \n", "None | \n", "3600 | \n", "False | \n", "
2015-03-09 21:00:45 | \n", "False | \n", "Fri Aug 14 17:12:23 +0000 2009 | \n", "False | \n", "False | \n", "Sp\u00e9cialiste dans le d\u00e9veloppement et le r\u00e9f\u00e9re... | \n", "18 | \n", "None | \n", "184 | \n", "None | \n", "131 | \n", "... | \n", "ACACAC | \n", "000000 | \n", "True | \n", "False | \n", "sudmedia66 | \n", "50127 | \n", "Paris | \n", "http://www.sud-media66.fr | \n", "3600 | \n", "False | \n", "
2015-03-09 21:00:45 | \n", "False | \n", "Sat Jan 22 18:47:53 +0000 2011 | \n", "False | \n", "False | \n", "None | \n", "2413 | \n", "None | \n", "130 | \n", "None | \n", "168 | \n", "... | \n", "DDEEF6 | \n", "333333 | \n", "True | \n", "False | \n", "ssantoss93 | \n", "11073 | \n", "Madrid | \n", "None | \n", "3600 | \n", "False | \n", "
3 rows \u00d7 38 columns
\n", "\n", " | tweets | \n", "
---|---|
screen_name | \n", "\n", " |
asdplayer55 | \n", "21 | \n", "
iphone_np | \n", "13 | \n", "
lexinerus | \n", "11 | \n", "
WhinyAppleWatch | \n", "10 | \n", "
niftytech_news | \n", "10 | \n", "
world_latest | \n", "9 | \n", "
JapanTechFeeds | \n", "8 | \n", "
asdplayer42 | \n", "8 | \n", "
technews_today | \n", "8 | \n", "
thinkb4talk07 | \n", "8 | \n", "
gachinko2 | \n", "8 | \n", "
smartclinic56 | \n", "8 | \n", "
anghel30637137 | \n", "7 | \n", "
sonuise | \n", "7 | \n", "
GET2GETHERKIM | \n", "7 | \n", "
iStantApple | \n", "7 | \n", "
aohhAREEYA | \n", "6 | \n", "
ios7italia | \n", "6 | \n", "
MetroPcTechs | \n", "6 | \n", "
Goem9 | \n", "6 | \n", "
HerodenMark | \n", "6 | \n", "
LinkBuilding7 | \n", "6 | \n", "
SquireStocks | \n", "6 | \n", "
Elia_Hicks | \n", "5 | \n", "
matematikogreni | \n", "5 | \n", "
\n", " | text | \n", "
---|---|
created_at | \n", "\n", " |
2015-03-09 21:00:46 | \n", "Why I wound up buying a Pebble\u200b Watch instead.... | \n", "
2015-03-09 21:00:46 | \n", "RT @BobScottCPA: How is the Apple Watch \"state... | \n", "
2015-03-09 21:00:46 | \n", "#AppleWatch Can't wait to wear one :) http://t... | \n", "
2015-03-09 21:00:46 | \n", "RT @MEMMOSdubai: Should you buy the $10,000 go... | \n", "
2015-03-09 21:00:46 | \n", "#setting4success Hands On With The Apple Watch... | \n", "
2015-03-09 21:00:46 | \n", "#Apple redefines itself as a luxury brand htt... | \n", "
2015-03-09 21:00:46 | \n", "RT @guardiantech: #Apple's new #MacBook comes ... | \n", "
2015-03-09 21:00:46 | \n", "RT @Fallonam: You guys we did this. We gave Ap... | \n", "
2015-03-09 21:00:46 | \n", "What Your Favorite Apps Look Like On Apple Wat... | \n", "
2015-03-09 21:00:47 | \n", "RT @TechCrunch: Apple Watch Will Ship On April... | \n", "
2015-03-09 21:00:47 | \n", "RT @selenalarson: For the price of a high-end ... | \n", "
2015-03-09 21:00:47 | \n", "RT @petercoffee: What if trusted data, from an... | \n", "
2015-03-09 21:00:47 | \n", "Apple Watch and new MacBook announcement: all ... | \n", "
2015-03-09 21:00:47 | \n", "RT @JamesTylerESPN: Louis van Gaal: definitely... | \n", "
2015-03-09 21:00:48 | \n", "@ZenTriathlon I'll just tow my Apple watch beh... | \n", "
2015-03-09 21:00:48 | \n", "$10k for a watch? ABSOLUTELY, APPLE! #nawwwwwt | \n", "
2015-03-09 21:00:48 | \n", "Someone give me $10,000 for a gold Apple watch... | \n", "
2015-03-09 21:00:48 | \n", "\"@AppStore: The Watch is coming. 4.24.15. htt... | \n", "
2015-03-09 21:00:48 | \n", "Check Out The Apple Watch [video] http://t.co/... | \n", "
2015-03-09 21:00:48 | \n", "RT @edaccessible: Use This Ingenious Trick to ... | \n", "
2015-03-09 21:00:48 | \n", "CNET: Apple Watch hands-on: Release date April... | \n", "
2015-03-09 21:00:48 | \n", "RT @PRNews: Top #PR Takeaways From the Apple W... | \n", "
2015-03-09 21:00:49 | \n", "RT @ClaraJeffery: If you spend $10k on a first... | \n", "
2015-03-09 21:00:49 | \n", "RT @AppStore: Mac in its purest form ever. The... | \n", "
2015-03-09 21:00:49 | \n", "RT @mashabletech: Should you buy the $10,000 g... | \n", "
\n", " | text | \n", "
---|---|
text | \n", "\n", " |
RT @AnnaKendrick47: We should be thanking Apple for launching the $10,000 \"apple watch\" as the new gold standard in douchebag detection. | \n", "246 | \n", "
RT @AppStore: The Watch is coming. 4.24.15. http://t.co/4iiurTDTt9\\nhttps://t.co/3Bedz37DAy | \n", "225 | \n", "
RT @sageboggs: Is there a way to sync my Google Glass to my Apple Watch? I want to ensure I won't kiss anyone for the rest of my life | \n", "38 | \n", "
RT @AppStore: Mac in its purest form ever. The new MacBook. http://t.co/U62E2iyNT6 http://t.co/jRtWddN0Wi | \n", "33 | \n", "
RT @verge: 10 things you can buy instead of a $10,000 Apple Watch http://t.co/skzHFWDCX0 http://t.co/RrZxqxN188 | \n", "28 | \n", "
RT @tomstandage: Genius from xkcd, as Apple prepares to launch its Watch http://t.co/OzcVuUoYJP http://t.co/nvhMdfw9vy | \n", "27 | \n", "
RT @ComplexMag: Everything you need to know about the Apple Watch and the New Gold MacBook: http://t.co/aylpX2MQi4 http://t.co/ORUNZwS0nh | \n", "27 | \n", "
RT @edaccessible: Use This Ingenious Trick to Choose the Right Apple Watch Size http://t.co/QMVOCKHRjx @TIME | \n", "27 | \n", "
RT @MEMMOSdubai: Should you buy the $10,000 gold Apple Watch? A helpful flowchart http://t.co/Crn3LPr7Ve @MEMMOSDubai #Dubai #UAE | \n", "23 | \n", "
RT @shutupmikeginn: sorry Apple, there's only one watch I'd pay $10,000 for: http://t.co/TC7PyMUXfY | \n", "21 | \n", "
RT @AppStore: The Watch is coming. 4.24.15. http://t.co/4iiurTDTt9\\nhttps://t.co/kkGlBBJIB9 | \n", "18 | \n", "
RT @WSJD: .@GeoffreyFowler says today's Apple Watch event was about \"quantity over quality\": http://t.co/FT8MI4sqlC http://t.co/c9v44NU4V3 | \n", "18 | \n", "
RT @RANsquawk: Loving my Apple Watch $AAPL http://t.co/c75QFoDSS3 | \n", "18 | \n", "
RT @TheOnion: From The Archives: Interim Apple Chief Under Fire After Unveiling Grotesque New MacBook http://t.co/OoLf5Wqe5q http://t.co/59\u2026 | \n", "17 | \n", "
RT @AppStore: The Watch is coming. 4.24.15. http://t.co/4iiurTDTt9\\nhttps://t.co/JY0qjXldir | \n", "17 | \n", "
RT @desusnice: JIGS UP RT @engadget: These $79 dongles will add more ports to Apple's new MacBook http://t.co/dLfNvRFk4n | \n", "16 | \n", "
RT @AppStore: The Watch is coming. 4.24.15. http://t.co/4iiurTDTt9\\nhttps://t.co/Z18Ue9rp7X | \n", "16 | \n", "
RT @SarcasticRover: I cost 250,000 Apple Watch Editions. | \n", "16 | \n", "
RT @waltmossberg: Apple Watch Selection Flowchart (Comic) http://t.co/TNfdhECT9P via @Recode http://t.co/jSHGFf4yIU | \n", "16 | \n", "
RT @robfee: Just preordered my $10,000 Apple Watch and I couldn't be more excited! http://t.co/r9qJ1lWIv1 | \n", "15 | \n", "
RT @andylassner: No way in hell I'm getting a $10,000 Apple watch unless a really rich talk show host buys me one. \\n\\ncc @TheEllenShow | \n", "13 | \n", "
RT @Rachelskirts: And nine\u2014nine Apple Watch Editions were gifted to the race of men, who above all else desire power. | \n", "13 | \n", "
RT @AppStore: The Watch is coming. 4.24.15. http://t.co/4iiurTDTt9\\nhttps://t.co/hI2YFOSf0f | \n", "12 | \n", "
RT @bmw: .@BMWi is excited to provide one of the apps for Apple Watch when it becomes available in April. Stay tuned! http://t.co/CSfKmneOAT | \n", "12 | \n", "
RT @TheTweetOfGod: The Apple Watch may become so addictive it keeps people from looking at what's truly important in life, like their iPhon\u2026 | \n", "12 | \n", "
We should be thanking Apple for launching the $10,000 "apple watch" as the new gold standard in douchebag detection.
— Anna Kendrick (@AnnaKendrick47) March 9, 2015
\n",
"\n",
"\n",
"When you take a closer look at some of the developed news stories, you also see sarcasm, unbelief, and even a bit of spam. Everything has a place on Twitter.\n",
"\n",
"Sentiment\n",
"---------\n",
"\n",
"Identifying sarcasm or irony is a very hard task for machines, as [it demands a lot of background knowledge](http://arstechnica.com/tech-policy/2014/06/us-secret-service-wants-software-to-detect-sarcasm-on-social-media/). We can, however, take a look on how sentiment evolved over time, and if in average the announcement of the new watch and laptop was positive or negative.\n",
"\n",
"Let's start by adding new columns to our `DataFrame` `en_text` that captures the sentiment of the tweets. But instead of using the regular polarity analyzer, we will use a `NaiveBayesAnalyzer()`."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from textblob.sentiments import NaiveBayesAnalyzer\n",
"analyzer = NaiveBayesAnalyzer()\n",
"\n",
"def extract_sentiment(value):\n",
" ...\n",
" return pd.Series([sentiment, pos_prob, neg_prob])\n",
"\n",
"en_text[...] = en_text.text.apply(extract_sentiment)\n",
"en_text[[\"text\", \"sentiment\", \"pos_prob\", \"neg_prob\"]].head(3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n", " | text | \n", "sentiment | \n", "pos_prob | \n", "neg_prob | \n", "
---|---|---|---|---|
created_at | \n", "\n", " | \n", " | \n", " | \n", " |
2015-03-09 21:00:46 | \n", "Why I wound up buying a Pebble\u200b Watch instead.... | \n", "pos | \n", "0.949290 | \n", "0.050710 | \n", "
2015-03-09 21:00:46 | \n", "RT @BobScottCPA: How is the Apple Watch \"state... | \n", "neg | \n", "0.260906 | \n", "0.739094 | \n", "
2015-03-09 21:00:46 | \n", "#AppleWatch Can't wait to wear one :) http://t... | \n", "neg | \n", "0.443928 | \n", "0.556072 | \n", "
\n", " | pos_prob | \n", "text | \n", "neg_prob | \n", "
---|---|---|---|
sentiment | \n", "\n", " | \n", " | \n", " |
neg | \n", "0.379798 | \n", "1057 | \n", "0.620202 | \n", "
pos | \n", "0.799055 | \n", "5623 | \n", "0.200945 | \n", "
\n", " | \n", " | neg_prob | \n", "pos_prob | \n", "text | \n", "
---|---|---|---|---|
keyword | \n", "sentiment | \n", "\n", " | \n", " | \n", " |
both | \n", "neg | \n", "0.734580 | \n", "0.265420 | \n", "9 | \n", "
pos | \n", "0.140977 | \n", "0.859023 | \n", "235 | \n", "|
macbook | \n", "neg | \n", "0.624145 | \n", "0.375855 | \n", "140 | \n", "
pos | \n", "0.183667 | \n", "0.816333 | \n", "724 | \n", "|
watch | \n", "neg | \n", "0.616332 | \n", "0.383668 | \n", "872 | \n", "
pos | \n", "0.206179 | \n", "0.793821 | \n", "4592 | \n", "