Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
APOD picture of 2015 - First steps
{
"cells": [
{
"cell_type": "code",
"execution_count": 67,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's read the data and have a look at it..."
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>fb_post_message</th>\n",
" <th>tw_likes</th>\n",
" <th>gp_plusones</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>419728</td>\n",
" <td>1-1-2015</td>\n",
" <td>NaN</td>\n",
" <td>1059</td>\n",
" <td>APOD: Vela Supernova Remnant (2015 Jan 01) Ima...</td>\n",
" <td>172</td>\n",
" <td>461.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>483486</td>\n",
" <td>2-1-2015</td>\n",
" <td>NaN</td>\n",
" <td>1376</td>\n",
" <td>APOD: At the Heart of Orion (2015 Jan 02) Imag...</td>\n",
" <td>217</td>\n",
" <td>539.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>464607</td>\n",
" <td>3-1-2015</td>\n",
" <td>NaN</td>\n",
" <td>438</td>\n",
" <td>APOD: Apollo 17: A Stereo View from Lunar Orbi...</td>\n",
" <td>170</td>\n",
" <td>247.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>465347</td>\n",
" <td>4-1-2015</td>\n",
" <td>NaN</td>\n",
" <td>3514</td>\n",
" <td>APOD: Crescent Rhea Occults Crescent Saturn (2...</td>\n",
" <td>300</td>\n",
" <td>507.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>522844</td>\n",
" <td>5-1-2015</td>\n",
" <td>NaN</td>\n",
" <td>1079</td>\n",
" <td>APOD: A Fox Fur, a Unicorn, and a Christmas Tr...</td>\n",
" <td>136</td>\n",
" <td>403.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id date ig_hearts fb_likes \\\n",
"0 419728 1-1-2015 NaN 1059 \n",
"1 483486 2-1-2015 NaN 1376 \n",
"2 464607 3-1-2015 NaN 438 \n",
"3 465347 4-1-2015 NaN 3514 \n",
"4 522844 5-1-2015 NaN 1079 \n",
"\n",
" fb_post_message tw_likes gp_plusones \n",
"0 APOD: Vela Supernova Remnant (2015 Jan 01) Ima... 172 461.0 \n",
"1 APOD: At the Heart of Orion (2015 Jan 02) Imag... 217 539.0 \n",
"2 APOD: Apollo 17: A Stereo View from Lunar Orbi... 170 247.0 \n",
"3 APOD: Crescent Rhea Occults Crescent Saturn (2... 300 507.0 \n",
"4 APOD: A Fox Fur, a Unicorn, and a Christmas Tr... 136 403.0 "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"alldata = pd.read_csv('data/APOD Data Release 2015 Final Basic.csv', delimiter=';')\n",
"alldata.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, we have an id and date and fb_post_message that are not really useful for the statistics but can be used to identify and describe the picture. Now let's have a look at the highest scores per social media. Save these values to do further statistics."
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>fb_post_message</th>\n",
" <th>tw_likes</th>\n",
" <th>gp_plusones</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>221</th>\n",
" <td>454197</td>\n",
" <td>13-8-2015</td>\n",
" <td>1573.0</td>\n",
" <td>16556</td>\n",
" <td>APOD: Moonless Meteors and the Milky Way (2015...</td>\n",
" <td>286</td>\n",
" <td>895.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>532208</td>\n",
" <td>29-9-2015</td>\n",
" <td>1964.0</td>\n",
" <td>13560</td>\n",
" <td>APOD: Supermoon Total Lunar Eclipse and Lightn...</td>\n",
" <td>400</td>\n",
" <td>1507.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>254</th>\n",
" <td>432723</td>\n",
" <td>15-9-2015</td>\n",
" <td>1439.0</td>\n",
" <td>11180</td>\n",
" <td>APOD: A Spiral Aurora over Iceland (2015 Sep 1...</td>\n",
" <td>280</td>\n",
" <td>1364.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>455608</td>\n",
" <td>16-2-2015</td>\n",
" <td>634.0</td>\n",
" <td>8564</td>\n",
" <td>APOD: M106: A Spiral Galaxy with a Strange Cen...</td>\n",
" <td>786</td>\n",
" <td>723.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>323</th>\n",
" <td>562062</td>\n",
" <td>23-11-2015</td>\n",
" <td>1904.0</td>\n",
" <td>8222</td>\n",
" <td>APOD: A 212-Hour Exposure of Orion (2015 Nov 2...</td>\n",
" <td>292</td>\n",
" <td>1333.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>67</th>\n",
" <td>513837</td>\n",
" <td>11-3-2015</td>\n",
" <td>890.0</td>\n",
" <td>7292</td>\n",
" <td>APOD: Volcano of Fire Erupts Under the Stars (...</td>\n",
" <td>219</td>\n",
" <td>1428.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>452402</td>\n",
" <td>27-7-2015</td>\n",
" <td>1023.0</td>\n",
" <td>7285</td>\n",
" <td>APOD: Milky Way and Aurora over Antarctica (20...</td>\n",
" <td>413</td>\n",
" <td>1492.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>469457</td>\n",
" <td>18-10-2015</td>\n",
" <td>2002.0</td>\n",
" <td>6678</td>\n",
" <td>APOD: Mammatus Clouds Over Saskatchewan (2015 ...</td>\n",
" <td>1812</td>\n",
" <td>1620.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>267</th>\n",
" <td>552551</td>\n",
" <td>28-9-2015</td>\n",
" <td>1652.0</td>\n",
" <td>6227</td>\n",
" <td>APOD: Total Lunar Eclipse over Waterton Lake (...</td>\n",
" <td>266</td>\n",
" <td>1322.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>261</th>\n",
" <td>450204</td>\n",
" <td>22-9-2015</td>\n",
" <td>1391.0</td>\n",
" <td>6045</td>\n",
" <td>APOD: Milky Way over Bosque Alegre Station in ...</td>\n",
" <td>209</td>\n",
" <td>1204.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id date ig_hearts fb_likes \\\n",
"221 454197 13-8-2015 1573.0 16556 \n",
"268 532208 29-9-2015 1964.0 13560 \n",
"254 432723 15-9-2015 1439.0 11180 \n",
"45 455608 16-2-2015 634.0 8564 \n",
"323 562062 23-11-2015 1904.0 8222 \n",
"67 513837 11-3-2015 890.0 7292 \n",
"204 452402 27-7-2015 1023.0 7285 \n",
"287 469457 18-10-2015 2002.0 6678 \n",
"267 552551 28-9-2015 1652.0 6227 \n",
"261 450204 22-9-2015 1391.0 6045 \n",
"\n",
" fb_post_message tw_likes gp_plusones \n",
"221 APOD: Moonless Meteors and the Milky Way (2015... 286 895.0 \n",
"268 APOD: Supermoon Total Lunar Eclipse and Lightn... 400 1507.0 \n",
"254 APOD: A Spiral Aurora over Iceland (2015 Sep 1... 280 1364.0 \n",
"45 APOD: M106: A Spiral Galaxy with a Strange Cen... 786 723.0 \n",
"323 APOD: A 212-Hour Exposure of Orion (2015 Nov 2... 292 1333.0 \n",
"67 APOD: Volcano of Fire Erupts Under the Stars (... 219 1428.0 \n",
"204 APOD: Milky Way and Aurora over Antarctica (20... 413 1492.0 \n",
"287 APOD: Mammatus Clouds Over Saskatchewan (2015 ... 1812 1620.0 \n",
"267 APOD: Total Lunar Eclipse over Waterton Lake (... 266 1322.0 \n",
"261 APOD: Milky Way over Bosque Alegre Station in ... 209 1204.0 "
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"top10data = alldata.sort_values(by='fb_likes', ascending=False).head(10)\n",
"top10data"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>fb_post_message</th>\n",
" <th>tw_likes</th>\n",
" <th>gp_plusones</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>356</th>\n",
" <td>471227</td>\n",
" <td>26-12-2015</td>\n",
" <td>2616.0</td>\n",
" <td>2719</td>\n",
" <td>APOD: Southern Craters and Galaxies (2015 Dec ...</td>\n",
" <td>207</td>\n",
" <td>1154.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>353</th>\n",
" <td>521901</td>\n",
" <td>23-12-2015</td>\n",
" <td>2475.0</td>\n",
" <td>4946</td>\n",
" <td>APOD: Geminid Meteors over Xinglong Observator...</td>\n",
" <td>163</td>\n",
" <td>908.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>346</th>\n",
" <td>772949</td>\n",
" <td>16-12-2015</td>\n",
" <td>2431.0</td>\n",
" <td>4211</td>\n",
" <td>APOD: The Horsehead Nebula (2015 Dec 16) Image...</td>\n",
" <td>193</td>\n",
" <td>840.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>359</th>\n",
" <td>476619</td>\n",
" <td>29-12-2015</td>\n",
" <td>2410.0</td>\n",
" <td>3572</td>\n",
" <td>APOD: Dust of the Orion Nebula (2015 Dec 29) I...</td>\n",
" <td>201</td>\n",
" <td>931.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>348</th>\n",
" <td>777064</td>\n",
" <td>18-12-2015</td>\n",
" <td>2180.0</td>\n",
" <td>2792</td>\n",
" <td>APOD: Herbig-Haro 24 (2015 Dec 18) Image Credi...</td>\n",
" <td>494</td>\n",
" <td>768.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>360</th>\n",
" <td>466684</td>\n",
" <td>30-12-2015</td>\n",
" <td>2112.0</td>\n",
" <td>2491</td>\n",
" <td>APOD: The Fox Fur Nebula (2015 Dec 30) Image C...</td>\n",
" <td>197</td>\n",
" <td>784.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>361</th>\n",
" <td>447897</td>\n",
" <td>31-12-2015</td>\n",
" <td>2101.0</td>\n",
" <td>2521</td>\n",
" <td>APOD: Solstice Sun at Lulworth Cove (2015 Dec ...</td>\n",
" <td>216</td>\n",
" <td>1070.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>469457</td>\n",
" <td>18-10-2015</td>\n",
" <td>2002.0</td>\n",
" <td>6678</td>\n",
" <td>APOD: Mammatus Clouds Over Saskatchewan (2015 ...</td>\n",
" <td>1812</td>\n",
" <td>1620.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>331</th>\n",
" <td>526671</td>\n",
" <td>1-12-2015</td>\n",
" <td>1993.0</td>\n",
" <td>2219</td>\n",
" <td>APOD: Nebulae in Aurigae (2015 Dec 01) Image C...</td>\n",
" <td>162</td>\n",
" <td>1058.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>532208</td>\n",
" <td>29-9-2015</td>\n",
" <td>1964.0</td>\n",
" <td>13560</td>\n",
" <td>APOD: Supermoon Total Lunar Eclipse and Lightn...</td>\n",
" <td>400</td>\n",
" <td>1507.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id date ig_hearts fb_likes \\\n",
"356 471227 26-12-2015 2616.0 2719 \n",
"353 521901 23-12-2015 2475.0 4946 \n",
"346 772949 16-12-2015 2431.0 4211 \n",
"359 476619 29-12-2015 2410.0 3572 \n",
"348 777064 18-12-2015 2180.0 2792 \n",
"360 466684 30-12-2015 2112.0 2491 \n",
"361 447897 31-12-2015 2101.0 2521 \n",
"287 469457 18-10-2015 2002.0 6678 \n",
"331 526671 1-12-2015 1993.0 2219 \n",
"268 532208 29-9-2015 1964.0 13560 \n",
"\n",
" fb_post_message tw_likes gp_plusones \n",
"356 APOD: Southern Craters and Galaxies (2015 Dec ... 207 1154.0 \n",
"353 APOD: Geminid Meteors over Xinglong Observator... 163 908.0 \n",
"346 APOD: The Horsehead Nebula (2015 Dec 16) Image... 193 840.0 \n",
"359 APOD: Dust of the Orion Nebula (2015 Dec 29) I... 201 931.0 \n",
"348 APOD: Herbig-Haro 24 (2015 Dec 18) Image Credi... 494 768.0 \n",
"360 APOD: The Fox Fur Nebula (2015 Dec 30) Image C... 197 784.0 \n",
"361 APOD: Solstice Sun at Lulworth Cove (2015 Dec ... 216 1070.0 \n",
"287 APOD: Mammatus Clouds Over Saskatchewan (2015 ... 1812 1620.0 \n",
"331 APOD: Nebulae in Aurigae (2015 Dec 01) Image C... 162 1058.0 \n",
"268 APOD: Supermoon Total Lunar Eclipse and Lightn... 400 1507.0 "
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"top10data = top10data.append(alldata.sort_values(by='ig_hearts', ascending=False).head(10))\n",
"top10data.tail(10)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>fb_post_message</th>\n",
" <th>tw_likes</th>\n",
" <th>gp_plusones</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>469457</td>\n",
" <td>18-10-2015</td>\n",
" <td>2002.0</td>\n",
" <td>6678</td>\n",
" <td>APOD: Mammatus Clouds Over Saskatchewan (2015 ...</td>\n",
" <td>1812</td>\n",
" <td>1620.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>245</th>\n",
" <td>378026</td>\n",
" <td>6-9-2015</td>\n",
" <td>1426.0</td>\n",
" <td>2389</td>\n",
" <td>APOD: Earthrise (2015 Sep 06) Image Credit: Ap...</td>\n",
" <td>1069</td>\n",
" <td>825.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>438541</td>\n",
" <td>19-4-2015</td>\n",
" <td>657.0</td>\n",
" <td>2131</td>\n",
" <td>APOD: Ring Galaxy AM 0644-741 from Hubble (201...</td>\n",
" <td>962</td>\n",
" <td>824.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>506466</td>\n",
" <td>2-2-2015</td>\n",
" <td>NaN</td>\n",
" <td>855</td>\n",
" <td>APOD: Titan Seas Reflect Sunlight (2015 Feb 02...</td>\n",
" <td>930</td>\n",
" <td>447.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>529720</td>\n",
" <td>5-2-2015</td>\n",
" <td>773.0</td>\n",
" <td>1976</td>\n",
" <td>APOD: M104: The Sombrero Galaxy (2015 Feb 05) ...</td>\n",
" <td>914</td>\n",
" <td>1254.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>417844</td>\n",
" <td>7-1-2015</td>\n",
" <td>909.0</td>\n",
" <td>1972</td>\n",
" <td>APOD: In the Arms of NGC 1097 (2015 Jan 09) Im...</td>\n",
" <td>839</td>\n",
" <td>660.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>376766</td>\n",
" <td>5-7-2015</td>\n",
" <td>NaN</td>\n",
" <td>3063</td>\n",
" <td>APOD: Zeta Oph: Runaway Star (2015 Jul 05) Ima...</td>\n",
" <td>790</td>\n",
" <td>918.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>455608</td>\n",
" <td>16-2-2015</td>\n",
" <td>634.0</td>\n",
" <td>8564</td>\n",
" <td>APOD: M106: A Spiral Galaxy with a Strange Cen...</td>\n",
" <td>786</td>\n",
" <td>723.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>327</th>\n",
" <td>490529</td>\n",
" <td>27-11-2015</td>\n",
" <td>NaN</td>\n",
" <td>2745</td>\n",
" <td>APOD: Gravity's Grin (2015 Nov 27) Image Credi...</td>\n",
" <td>784</td>\n",
" <td>743.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>92</th>\n",
" <td>410857</td>\n",
" <td>5-4-2015</td>\n",
" <td>883.0</td>\n",
" <td>2888</td>\n",
" <td>APOD: Saturn, Tethys, Rings, and Shadows (2015...</td>\n",
" <td>755</td>\n",
" <td>807.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id date ig_hearts fb_likes \\\n",
"287 469457 18-10-2015 2002.0 6678 \n",
"245 378026 6-9-2015 1426.0 2389 \n",
"106 438541 19-4-2015 657.0 2131 \n",
"31 506466 2-2-2015 NaN 855 \n",
"34 529720 5-2-2015 773.0 1976 \n",
"6 417844 7-1-2015 909.0 1972 \n",
"182 376766 5-7-2015 NaN 3063 \n",
"45 455608 16-2-2015 634.0 8564 \n",
"327 490529 27-11-2015 NaN 2745 \n",
"92 410857 5-4-2015 883.0 2888 \n",
"\n",
" fb_post_message tw_likes gp_plusones \n",
"287 APOD: Mammatus Clouds Over Saskatchewan (2015 ... 1812 1620.0 \n",
"245 APOD: Earthrise (2015 Sep 06) Image Credit: Ap... 1069 825.0 \n",
"106 APOD: Ring Galaxy AM 0644-741 from Hubble (201... 962 824.0 \n",
"31 APOD: Titan Seas Reflect Sunlight (2015 Feb 02... 930 447.0 \n",
"34 APOD: M104: The Sombrero Galaxy (2015 Feb 05) ... 914 1254.0 \n",
"6 APOD: In the Arms of NGC 1097 (2015 Jan 09) Im... 839 660.0 \n",
"182 APOD: Zeta Oph: Runaway Star (2015 Jul 05) Ima... 790 918.0 \n",
"45 APOD: M106: A Spiral Galaxy with a Strange Cen... 786 723.0 \n",
"327 APOD: Gravity's Grin (2015 Nov 27) Image Credi... 784 743.0 \n",
"92 APOD: Saturn, Tethys, Rings, and Shadows (2015... 755 807.0 "
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"top10data = top10data.append(alldata.sort_values(by='tw_likes', ascending=False).head(10))\n",
"top10data.tail(10)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>date</th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>fb_post_message</th>\n",
" <th>tw_likes</th>\n",
" <th>gp_plusones</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>142</th>\n",
" <td>409084</td>\n",
" <td>25-5-2015</td>\n",
" <td>947.0</td>\n",
" <td>3784</td>\n",
" <td>APOD: The Galaxy Tree (2015 May 25) Image Cred...</td>\n",
" <td>281</td>\n",
" <td>1962.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>281</th>\n",
" <td>486230</td>\n",
" <td>12-10-2015</td>\n",
" <td>1210.0</td>\n",
" <td>2164</td>\n",
" <td>APOD: Galaxy, Stars, and Dust (2015 Oct 12) Im...</td>\n",
" <td>164</td>\n",
" <td>1681.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>469457</td>\n",
" <td>18-10-2015</td>\n",
" <td>2002.0</td>\n",
" <td>6678</td>\n",
" <td>APOD: Mammatus Clouds Over Saskatchewan (2015 ...</td>\n",
" <td>1812</td>\n",
" <td>1620.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>277</th>\n",
" <td>483361</td>\n",
" <td>8-10-2015</td>\n",
" <td>1268.0</td>\n",
" <td>2971</td>\n",
" <td>APOD: M83: The Thousand-Ruby Galaxy (2015 Oct ...</td>\n",
" <td>217</td>\n",
" <td>1607.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>511111</td>\n",
" <td>13-4-2015</td>\n",
" <td>827.0</td>\n",
" <td>4394</td>\n",
" <td>APOD: Milky Way over Erupting Volcano (2015 Ap...</td>\n",
" <td>281</td>\n",
" <td>1586.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>296</th>\n",
" <td>483675</td>\n",
" <td>27-10-2015</td>\n",
" <td>1748.0</td>\n",
" <td>4283</td>\n",
" <td>APOD: Bright from the Heart Nebula (2015 Oct 2...</td>\n",
" <td>182</td>\n",
" <td>1573.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>424641</td>\n",
" <td>4-5-2015</td>\n",
" <td>801.0</td>\n",
" <td>3438</td>\n",
" <td>APOD: An Unexpected Aurora over Norway (2015 M...</td>\n",
" <td>245</td>\n",
" <td>1517.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>532208</td>\n",
" <td>29-9-2015</td>\n",
" <td>1964.0</td>\n",
" <td>13560</td>\n",
" <td>APOD: Supermoon Total Lunar Eclipse and Lightn...</td>\n",
" <td>400</td>\n",
" <td>1507.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>452402</td>\n",
" <td>27-7-2015</td>\n",
" <td>1023.0</td>\n",
" <td>7285</td>\n",
" <td>APOD: Milky Way and Aurora over Antarctica (20...</td>\n",
" <td>413</td>\n",
" <td>1492.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>299</th>\n",
" <td>464887</td>\n",
" <td>30-10-2015</td>\n",
" <td>1691.0</td>\n",
" <td>4880</td>\n",
" <td>APOD: The Witch Head Nebula (2015 Oct 30) Imag...</td>\n",
" <td>183</td>\n",
" <td>1483.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id date ig_hearts fb_likes \\\n",
"142 409084 25-5-2015 947.0 3784 \n",
"281 486230 12-10-2015 1210.0 2164 \n",
"287 469457 18-10-2015 2002.0 6678 \n",
"277 483361 8-10-2015 1268.0 2971 \n",
"100 511111 13-4-2015 827.0 4394 \n",
"296 483675 27-10-2015 1748.0 4283 \n",
"121 424641 4-5-2015 801.0 3438 \n",
"268 532208 29-9-2015 1964.0 13560 \n",
"204 452402 27-7-2015 1023.0 7285 \n",
"299 464887 30-10-2015 1691.0 4880 \n",
"\n",
" fb_post_message tw_likes gp_plusones \n",
"142 APOD: The Galaxy Tree (2015 May 25) Image Cred... 281 1962.0 \n",
"281 APOD: Galaxy, Stars, and Dust (2015 Oct 12) Im... 164 1681.0 \n",
"287 APOD: Mammatus Clouds Over Saskatchewan (2015 ... 1812 1620.0 \n",
"277 APOD: M83: The Thousand-Ruby Galaxy (2015 Oct ... 217 1607.0 \n",
"100 APOD: Milky Way over Erupting Volcano (2015 Ap... 281 1586.0 \n",
"296 APOD: Bright from the Heart Nebula (2015 Oct 2... 182 1573.0 \n",
"121 APOD: An Unexpected Aurora over Norway (2015 M... 245 1517.0 \n",
"268 APOD: Supermoon Total Lunar Eclipse and Lightn... 400 1507.0 \n",
"204 APOD: Milky Way and Aurora over Antarctica (20... 413 1492.0 \n",
"299 APOD: The Witch Head Nebula (2015 Oct 30) Imag... 183 1483.0 "
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"top10data = top10data.append(alldata.sort_values(by='gp_plusones', ascending=False).head(10))\n",
"top10data.tail(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's make a combined top 10. Every count is normalized and after that we sum up the total score with equal weights. First let's see if we have any nan's in the matrix."
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"id 0\n",
"date 0\n",
"ig_hearts 95\n",
"fb_likes 0\n",
"fb_post_message 0\n",
"tw_likes 0\n",
"gp_plusones 1\n",
"dtype: int64\n",
"id 363\n",
"date 363\n",
"ig_hearts 268\n",
"fb_likes 363\n",
"fb_post_message 363\n",
"tw_likes 363\n",
"gp_plusones 362\n",
"dtype: int64\n"
]
}
],
"source": [
"print alldata.isnull().sum()\n",
"print alldata.count()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Warning.. assumption ahead..**\n",
"\n",
"Wow.. Instagram is missing 95 picture votes.. there are a lot of ways to deal with this but I will fake the data and say that if we have no data we use the average score of the instagram votes. The same applies to the one missing Google Plus vote."
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"toptendata = alldata.fillna(alldata.mean())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, now normalize and calculate the 10 winners.."
]
},
{
"cell_type": "code",
"execution_count": 107,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ig_hearts</th>\n",
" <th>fb_likes</th>\n",
" <th>gp_plusones</th>\n",
" <th>tw_likes</th>\n",
" <th>score</th>\n",
" <th>id</th>\n",
" <th>fb_post_message</th>\n",
" <th>date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>287</th>\n",
" <td>0.430770</td>\n",
" <td>0.271481</td>\n",
" <td>0.479683</td>\n",
" <td>0.850968</td>\n",
" <td>2.032901</td>\n",
" <td>469457</td>\n",
" <td>APOD: Mammatus Clouds Over Saskatchewan (2015 ...</td>\n",
" <td>18-10-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>268</th>\n",
" <td>0.413911</td>\n",
" <td>0.694104</td>\n",
" <td>0.422089</td>\n",
" <td>0.071718</td>\n",
" <td>1.601822</td>\n",
" <td>532208</td>\n",
" <td>APOD: Supermoon Total Lunar Eclipse and Lightn...</td>\n",
" <td>29-9-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>221</th>\n",
" <td>0.240442</td>\n",
" <td>0.878089</td>\n",
" <td>0.110162</td>\n",
" <td>0.008804</td>\n",
" <td>1.237497</td>\n",
" <td>454197</td>\n",
" <td>APOD: Moonless Meteors and the Milky Way (2015...</td>\n",
" <td>13-8-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>323</th>\n",
" <td>0.387292</td>\n",
" <td>0.366298</td>\n",
" <td>0.333404</td>\n",
" <td>0.012115</td>\n",
" <td>1.099109</td>\n",
" <td>562062</td>\n",
" <td>APOD: A 212-Hour Exposure of Orion (2015 Nov 2...</td>\n",
" <td>23-11-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>254</th>\n",
" <td>0.180992</td>\n",
" <td>0.547949</td>\n",
" <td>0.349204</td>\n",
" <td>0.005493</td>\n",
" <td>1.083637</td>\n",
" <td>432723</td>\n",
" <td>APOD: A Spiral Aurora over Iceland (2015 Sep 1...</td>\n",
" <td>15-9-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>280</th>\n",
" <td>0.178330</td>\n",
" <td>0.183972</td>\n",
" <td>0.388959</td>\n",
" <td>0.217413</td>\n",
" <td>0.968674</td>\n",
" <td>421057</td>\n",
" <td>APOD: In the Center of the Trifid Nebula (2015...</td>\n",
" <td>11-10-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>356</th>\n",
" <td>0.703174</td>\n",
" <td>0.028359</td>\n",
" <td>0.242170</td>\n",
" <td>-0.034794</td>\n",
" <td>0.938910</td>\n",
" <td>471227</td>\n",
" <td>APOD: Southern Craters and Galaxies (2015 Dec ...</td>\n",
" <td>26-12-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>353</th>\n",
" <td>0.640619</td>\n",
" <td>0.165119</td>\n",
" <td>0.116788</td>\n",
" <td>-0.059077</td>\n",
" <td>0.863449</td>\n",
" <td>521901</td>\n",
" <td>APOD: Geminid Meteors over Xinglong Observator...</td>\n",
" <td>23-12-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>274</th>\n",
" <td>0.287025</td>\n",
" <td>0.201719</td>\n",
" <td>0.392527</td>\n",
" <td>-0.030379</td>\n",
" <td>0.850893</td>\n",
" <td>491593</td>\n",
" <td>APOD: Orion Over and Under Tibet (2015 Oct 05)...</td>\n",
" <td>5-10-2015</td>\n",
" </tr>\n",
" <tr>\n",
" <th>296</th>\n",
" <td>0.318081</td>\n",
" <td>0.124404</td>\n",
" <td>0.455728</td>\n",
" <td>-0.048591</td>\n",
" <td>0.849622</td>\n",
" <td>483675</td>\n",
" <td>APOD: Bright from the Heart Nebula (2015 Oct 2...</td>\n",
" <td>27-10-2015</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ig_hearts fb_likes gp_plusones tw_likes score id \\\n",
"287 0.430770 0.271481 0.479683 0.850968 2.032901 469457 \n",
"268 0.413911 0.694104 0.422089 0.071718 1.601822 532208 \n",
"221 0.240442 0.878089 0.110162 0.008804 1.237497 454197 \n",
"323 0.387292 0.366298 0.333404 0.012115 1.099109 562062 \n",
"254 0.180992 0.547949 0.349204 0.005493 1.083637 432723 \n",
"280 0.178330 0.183972 0.388959 0.217413 0.968674 421057 \n",
"356 0.703174 0.028359 0.242170 -0.034794 0.938910 471227 \n",
"353 0.640619 0.165119 0.116788 -0.059077 0.863449 521901 \n",
"274 0.287025 0.201719 0.392527 -0.030379 0.850893 491593 \n",
"296 0.318081 0.124404 0.455728 -0.048591 0.849622 483675 \n",
"\n",
" fb_post_message date \n",
"287 APOD: Mammatus Clouds Over Saskatchewan (2015 ... 18-10-2015 \n",
"268 APOD: Supermoon Total Lunar Eclipse and Lightn... 29-9-2015 \n",
"221 APOD: Moonless Meteors and the Milky Way (2015... 13-8-2015 \n",
"323 APOD: A 212-Hour Exposure of Orion (2015 Nov 2... 23-11-2015 \n",
"254 APOD: A Spiral Aurora over Iceland (2015 Sep 1... 15-9-2015 \n",
"280 APOD: In the Center of the Trifid Nebula (2015... 11-10-2015 \n",
"356 APOD: Southern Craters and Galaxies (2015 Dec ... 26-12-2015 \n",
"353 APOD: Geminid Meteors over Xinglong Observator... 23-12-2015 \n",
"274 APOD: Orion Over and Under Tibet (2015 Oct 05)... 5-10-2015 \n",
"296 APOD: Bright from the Heart Nebula (2015 Oct 2... 27-10-2015 "
]
},
"execution_count": 107,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"normalized_data = toptendata[['ig_hearts', 'fb_likes', 'gp_plusones', 'tw_likes']].apply(lambda x: (x - x.mean()) / (x.max() - x.min()))\n",
"normalized_data['score'] = normalized_data['ig_hearts'] + normalized_data['fb_likes'] + normalized_data['gp_plusones'] + normalized_data['tw_likes']\n",
"normalized_data['id'] = toptendata['id']\n",
"normalized_data['fb_post_message'] = toptendata['fb_post_message']\n",
"normalized_data['date'] = toptendata['date']\n",
"normalized_data.sort_values(by='score', ascending=False).head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The winners are...\n",
"\n",
" \n",
" ### Number 3...\n",
" \n",
"![APOD of 2015](https://apod.nasa.gov/apod/image/1508/viz_2013_08_08-14_Perseidy_1500.jpg)\n",
" \n",
" ### Number 2...\n",
" \n",
"![APOD of 2015](https://apod.nasa.gov/apod/image/1509/LightningEclipse_Hervas_960.jpg)\n",
" \n",
" ### And number 1...\n",
" \n",
"![APOD of 2015](https://apod.nasa.gov/apod/image/1510/mammatus_lindsay_960.jpg)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.