Skip to content

Instantly share code, notes, and snippets.

@metasyn
Last active August 29, 2015 14:19
Show Gist options
  • Save metasyn/51bc4f49af0d32df3c6a to your computer and use it in GitHub Desktop.
Save metasyn/51bc4f49af0d32df3c6a to your computer and use it in GitHub Desktop.
LDI
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Linguistic Diversity Index](http://en.wikipedia.org/wiki/Linguistic_diversity_index)\n",
"\n",
">Greenberg's Diversity Index (LDI) is the probability that two people selected from the population at random will have different mother tongues; it therefore ranges from 0 (everyone has the same mother tongue) to 1 (no two people have the same mother tongue).\n",
"\n",
"So we got them from Wikipedia and let's take a look. \n",
"\n",
"Made by Xander Johnson (metasyn.pw)"
]
},
{
"cell_type": "code",
"execution_count": 197,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import seaborn as sns\n",
"import plotly.plotly as py \n",
"from plotly.graph_objs import *\n",
"\n",
"% matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scrape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"// http://en.wikipedia.org/wiki/Linguistic_diversity_index\n",
"\n",
"// initalize\n",
"var array = []\n",
"\n",
"// get those values with our good friend jQuery\n",
"$.each($('table tbody tr'), function() {\n",
" var ldi = $(this).find('td:last').html()\n",
" array.push({country: $(this).find('a').html(), \n",
" ldi: parseFloat(ldi) ? ldi:\"None\"});\n",
"});\n",
"\n",
"// simulate download\n",
"var stringed = JSON.stringify(array)\n",
"var b = new Blob([stringed])\n",
"var url = URL.createObjectURL(b)\n",
"var a = document.createElement('a');\n",
"a.href = url;\n",
"document.body.appendChild(a);\n",
"a.click();\n",
"\n",
"// copy & paste"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%javascript\n",
"\n",
"// http://en.wikipedia.org/wiki/Linguistic_diversity_index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clean"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data = [{\"country\":\"Papua New Guinea\",\"ldi\":\".990\"},{\"country\":\"Vanuatu\",\"ldi\":\".972\"},{\"country\":\"Solomon Islands\",\"ldi\":\".965\"},{\"country\":\"Tanzania\",\"ldi\":\".965\"},{\"country\":\"Central African Republic\",\"ldi\":\".960\"},{\"country\":\"Chad\",\"ldi\":\".950\"},{\"country\":\"Democratic Republic of the Congo\",\"ldi\":\".948\"},{\"country\":\"Cameroon\",\"ldi\":\".942\"},{\"country\":\"India\",\"ldi\":\".930\"},{\"country\":\"Mozambique\",\"ldi\":\".929\"},{\"country\":\"Uganda\",\"ldi\":\".928\"},{\"country\":\"Gabon\",\"ldi\":\".919\"},{\"country\":\"Côte d'Ivoire\",\"ldi\":\".917\"},{\"country\":\"Liberia\",\"ldi\":\".912\"},{\"country\":\"Angola\",\"ldi\":\".901\"},{\"country\":\"Kenya\",\"ldi\":\".901\"},{\"country\":\"Togo\",\"ldi\":\".897\"},{\"country\":\"Timor-Leste\",\"ldi\":\".897\"},{\"country\":\"Mali\",\"ldi\":\".876\"},{\"country\":\"Nigeria\",\"ldi\":\".870\"},{\"country\":\"South Africa\",\"ldi\":\".869\"},{\"country\":\"Zambia\",\"ldi\":\".855\"},{\"country\":\"Guinea-Bissau\",\"ldi\":\".853\"},{\"country\":\"Philippines\",\"ldi\":\".849\"},{\"country\":\"Bhutan\",\"ldi\":\".846\"},{\"country\":\"Indonesia\",\"ldi\":\".846\"},{\"country\":\"Ethiopia\",\"ldi\":\".843\"},{\"country\":\"Congo\",\"ldi\":\".820\"},{\"country\":\"Sierra Leone\",\"ldi\":\".817\"},{\"country\":\"Namibia\",\"ldi\":\".808\"},{\"country\":\"Ghana\",\"ldi\":\".805\"},{\"country\":\"Iran\",\"ldi\":\".797\"},{\"country\":\"Federated States of Micronesia\",\"ldi\":\".792\"},{\"country\":\"Suriname\",\"ldi\":\".788\"},{\"country\":\"Benin\",\"ldi\":\".785\"},{\"country\":\"United Arab Emirates\",\"ldi\":\".777\"},{\"country\":\"Burkina Faso\",\"ldi\":\".773\"},{\"country\":\"Senegal\",\"ldi\":\".772\"},{\"country\":\"Pakistan\",\"ldi\":\".762\"},{\"country\":\"Malaysia\",\"ldi\":\".758\"},{\"country\":\"Thailand\",\"ldi\":\".753\"},{\"country\":\"Eritrea\",\"ldi\":\".749\"},{\"country\":\"Gambia\",\"ldi\":\".748\"},{\"country\":\"Guinea\",\"ldi\":\".748\"},{\"country\":\"Singapore\",\"ldi\":\".748\"},{\"country\":\"Nepal\",\"ldi\":\".742\"},{\"country\":\"Belgium\",\"ldi\":\".734\"},{\"country\":\"Afghanistan\",\"ldi\":\".732\"},{\"country\":\"Kazakhstan\",\"ldi\":\".701\"},{\"country\":\"Trinidad and Tobago\",\"ldi\":\".696\"},{\"country\":\"Belize\",\"ldi\":\".693\"},{\"country\":\"Oman\",\"ldi\":\".693\"},{\"country\":\"Guatemala\",\"ldi\":\".691\"},{\"country\":\"Bolivia\",\"ldi\":\".680\"},{\"country\":\"Laos\",\"ldi\":\".678\"},{\"country\":\"Kyrgyzstan\",\"ldi\":\".670\"},{\"country\":\"Jordan\",\"ldi\":\".666\"},{\"country\":\"Israel\",\"ldi\":\".665\"},{\"country\":\"Bahrain\",\"ldi\":\".663\"},{\"country\":\"Norway\",\"ldi\":\".657\"},{\"country\":\"Madagascar\",\"ldi\":\".656\"},{\"country\":\"Niger\",\"ldi\":\".646\"},{\"country\":\"Mauritius\",\"ldi\":\".641\"},{\"country\":\"Saudi Arabia\",\"ldi\":\".609\"},{\"country\":\"Qatar\",\"ldi\":\".608\"},{\"country\":\"Fiji\",\"ldi\":\".607\"},{\"country\":\"Nauru\",\"ldi\":\".596\"},{\"country\":\"Latvia\",\"ldi\":\".595\"},{\"country\":\"Italy\",\"ldi\":\".593\"},{\"country\":\"Djibouti\",\"ldi\":\".592\"},{\"country\":\"Moldova\",\"ldi\":\".589\"},{\"country\":\"Sudan\",\"ldi\":\".587\"},{\"country\":\"Yemen\",\"ldi\":\".579\"},{\"country\":\"Georgia\",\"ldi\":\".576\"},{\"country\":\"Andorra\",\"ldi\":\".574\"},{\"country\":\"Macedonia\",\"ldi\":\".566\"},{\"country\":\"Kuwait\",\"ldi\":\".556\"},{\"country\":\"Comoros\",\"ldi\":\".551\"},{\"country\":\"Canada\",\"ldi\":\".549\"},{\"country\":\"Switzerland\",\"ldi\":\".547\"},{\"country\":\"Cayman Islands\",\"ldi\":\".547\"},{\"country\":\"Austria\",\"ldi\":\".540\"},{\"country\":\"Zimbabwe\",\"ldi\":\".526\"},{\"country\":\"Monaco\",\"ldi\":\".521\"},{\"country\":\"Myanmar\",\"ldi\":\".521\"},{\"country\":\"Malawi\",\"ldi\":\".519\"},{\"country\":\"Egypt\",\"ldi\":\".509\"},{\"country\":\"Syrian Arab Republic\",\"ldi\":\".503\"},{\"country\":\"Luxembourg\",\"ldi\":\".498\"},{\"country\":\"Gibraltar\",\"ldi\":\".498\"},{\"country\":\"San Marino\",\"ldi\":\".494\"},{\"country\":\"Ukraine\",\"ldi\":\".492\"},{\"country\":\"China\",\"ldi\":\".491\"},{\"country\":\"Iraq\",\"ldi\":\".484\"},{\"country\":\"Tajikistan\",\"ldi\":\".482\"},{\"country\":\"Estonia\",\"ldi\":\".476\"},{\"country\":\"Morocco\",\"ldi\":\".466\"},{\"country\":\"Brunei Darussalam\",\"ldi\":\".456\"},{\"country\":\"Equatorial Guinea\",\"ldi\":\".453\"},{\"country\":\"Botswana\",\"ldi\":\".444\"},{\"country\":\"Spain\",\"ldi\":\".438\"},{\"country\":\"Uzbekistan\",\"ldi\":\".428\"},{\"country\":\"Bosnia and Herzegovina\",\"ldi\":\".416\"},{\"country\":\"Belarus\",\"ldi\":\".397\"},{\"country\":\"Netherlands\",\"ldi\":\".389\"},{\"country\":\"Sao Tome and Principe\",\"ldi\":\".389\"},{\"country\":\"Aruba\",\"ldi\":\".387\"},{\"country\":\"Bahamas\",\"ldi\":\".386\"},{\"country\":\"Turkmenistan\",\"ldi\":\".386\"},{\"country\":\"Cook Islands\",\"ldi\":\".379\"},{\"country\":\"Peru\",\"ldi\":\".376\"},{\"country\":\"Azerbaijan\",\"ldi\":\".373\"},{\"country\":\"Cyprus\",\"ldi\":\".366\"},{\"country\":\"Libyan Arab Jamahiriya\",\"ldi\":\".362\"},{\"country\":\"Serbia\",\"ldi\":\".359\"},{\"country\":\"United States of America\",\"ldi\":\".353\"},{\"country\":\"Paraguay\",\"ldi\":\".347\"},{\"country\":\"Lithuania\",\"ldi\":\".339\"},{\"country\":\"Bangladesh\",\"ldi\":\".332\"},{\"country\":\"Mongolia\",\"ldi\":\".331\"},{\"country\":\"Panama\",\"ldi\":\".324\"},{\"country\":\"Dominica\",\"ldi\":\".313\"},{\"country\":\"Algeria\",\"ldi\":\".313\"},{\"country\":\"Sri Lanka\",\"ldi\":\".313\"},{\"country\":\"Slovakia\",\"ldi\":\".307\"},{\"country\":\"Turkey\",\"ldi\":\".289\"},{\"country\":\"Russian Federation\",\"ldi\":\".283\"},{\"country\":\"France\",\"ldi\":\".272\"},{\"country\":\"Netherlands Antilles\",\"ldi\":\".266\"},{\"country\":\"Ecuador\",\"ldi\":\".264\"},{\"country\":\"Lesotho\",\"ldi\":\".260\"},{\"country\":\"Albania\",\"ldi\":\".257\"},{\"country\":\"Viet Nam\",\"ldi\":\".234\"},{\"country\":\"Swaziland\",\"ldi\":\".228\"},{\"country\":\"Bulgaria\",\"ldi\":\".224\"},{\"country\":\"Ireland\",\"ldi\":\".223\"},{\"country\":\"Argentina\",\"ldi\":\".213\"},{\"country\":\"Palestine\",\"ldi\":\".208\"},{\"country\":\"Germany\",\"ldi\":\".189\"},{\"country\":\"Somalia\",\"ldi\":\".179\"},{\"country\":\"Greece\",\"ldi\":\".175\"},{\"country\":\"Slovenia\",\"ldi\":\".174\"},{\"country\":\"Armenia\",\"ldi\":\".174\"},{\"country\":\"Mauritania\",\"ldi\":\".172\"},{\"country\":\"Romania\",\"ldi\":\".168\"},{\"country\":\"Sweden\",\"ldi\":\".167\"},{\"country\":\"British Virgin Islands\",\"ldi\":\".167\"},{\"country\":\"Lebanon\",\"ldi\":\".161\"},{\"country\":\"Hungary\",\"ldi\":\".158\"},{\"country\":\"Cambodia\",\"ldi\":\".157\"},{\"country\":\"Turks and Caicos Islands\",\"ldi\":\".145\"},{\"country\":\"Anguilla\",\"ldi\":\".140\"},{\"country\":\"Finland\",\"ldi\":\".140\"},{\"country\":\"Tuvalu\",\"ldi\":\".139\"},{\"country\":\"United Kingdom\",\"ldi\":\".139\"},{\"country\":\"Mexico\",\"ldi\":\".135\"},{\"country\":\"Liechtenstein\",\"ldi\":\".128\"},{\"country\":\"Australia\",\"ldi\":\".126\"},{\"country\":\"New Zealand\",\"ldi\":\".102\"},{\"country\":\"Uruguay\",\"ldi\":\".092\"},{\"country\":\"Barbados\",\"ldi\":\".091\"},{\"country\":\"Croatia\",\"ldi\":\".087\"},{\"country\":\"Nicaragua\",\"ldi\":\".081\"},{\"country\":\"Guyana\",\"ldi\":\".078\"},{\"country\":\"Palau\",\"ldi\":\".077\"},{\"country\":\"Niue\",\"ldi\":\".071\"},{\"country\":\"Cape Verde\",\"ldi\":\".070\"},{\"country\":\"Czech Republic\",\"ldi\":\".069\"},{\"country\":\"Seychelles\",\"ldi\":\".067\"},{\"country\":\"Grenada\",\"ldi\":\".064\"},{\"country\":\"Poland\",\"ldi\":\".060\"},{\"country\":\"Antigua and Barbuda\",\"ldi\":\".057\"},{\"country\":\"Honduras\",\"ldi\":\".056\"},{\"country\":\"Tokelau\",\"ldi\":\".054\"},{\"country\":\"Dominican Republic\",\"ldi\":\".053\"},{\"country\":\"Denmark\",\"ldi\":\".051\"},{\"country\":\"Costa Rica\",\"ldi\":\".050\"},{\"country\":\"Chile\",\"ldi\":\".034\"},{\"country\":\"Kiribati\",\"ldi\":\".033\"},{\"country\":\"Brazil\",\"ldi\":\".032\"},{\"country\":\"Colombia\",\"ldi\":\".030\"},{\"country\":\"Japan\",\"ldi\":\".028\"},{\"country\":\"Marshall Islands\",\"ldi\":\".027\"},{\"country\":\"Montserrat\",\"ldi\":\".026\"},{\"country\":\"Venezuela\",\"ldi\":\".026\"},{\"country\":\"Portugal\",\"ldi\":\".022\"},{\"country\":\"Saint Lucia\",\"ldi\":\".020\"},{\"country\":\"Iceland\",\"ldi\":\".019\"},{\"country\":\"Malta\",\"ldi\":\".016\"},{\"country\":\"Tonga\",\"ldi\":\".014\"},{\"country\":\"Tunisia\",\"ldi\":\".012\"},{\"country\":\"Jamaica\",\"ldi\":\".011\"},{\"country\":\"Saint Kitts and Nevis\",\"ldi\":\".010\"},{\"country\":\"Maldives\",\"ldi\":\".010\"},{\"country\":\"Saint Vincent and the Grenadines\",\"ldi\":\".009\"},{\"country\":\"El Salvador\",\"ldi\":\".004\"},{\"country\":\"Burundi\",\"ldi\":\".004\"},{\"country\":\"Rwanda\",\"ldi\":\".004\"},{\"country\":\"South Korea\",\"ldi\":\".003\"},{\"country\":\"Samoa\",\"ldi\":\".002\"},{\"country\":\"Cuba\",\"ldi\":\".001\"},{\"country\":\"Haiti\",\"ldi\":\"None\"},{\"country\":\"Saint Helena\",\"ldi\":\"None\"},{\"country\":\"Holy See\",\"ldi\":\"None\"},{\"country\":\"Montenegro\",\"ldi\":\"None\"},{\"country\":\"Bermuda\",\"ldi\":\"None\"},{\"country\":\"Hong Kong\",\"ldi\":\"None\"},{\"country\":\"Macao\",\"ldi\":\"None\"},{\"country\":\"North Korea\",\"ldi\":\"None\"}]\n",
"for d in data:\n",
" d['country'] = d['country'].decode('utf-8')\n",
" if \"Ivoire\" in d['country']:\n",
" d['country'] = u\"Cote d'Ivoire\"\n",
" if d['ldi'] == 'None':\n",
" d['ldi'] = 0\n",
" else:\n",
" d['ldi'] = float(d['ldi'])\n",
" # damn cote"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'country': u'Solomon Islands', 'ldi': 0.965}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[2]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.DataFrame(data)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>country</th>\n",
" <th>ldi</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td> Papua New Guinea</td>\n",
" <td> 0.990</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td> Vanuatu</td>\n",
" <td> 0.972</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" country ldi\n",
"0 Papua New Guinea 0.990\n",
"1 Vanuatu 0.972"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(2)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[<matplotlib.axes.AxesSubplot object at 0x10e637550>]], dtype=object)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": [
"iVBORw0KGgoAAAANSUhEUgAAAXQAAAEICAYAAABPgw/pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\n",
"AAALEgAACxIB0t1+/AAAEuVJREFUeJzt3X9wlPWdwPHPsxtCIOSHnEV7lyOYLaCOcypmrQcG5Aw2\n",
"OrH8SBRiJBThQEYrbZg2AcwPGaqpHE49FQ8zLZQU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XOfua6zW4qqrrtr9wgsv3ON2uz2zZs3a\n",
"KSJSUFDweGZm5hZ7p46M7n4uLvxvNe+TinS/Fr/4xS/mLFq06FnTNI0xY8a8OX78+FfsnjlSuluL\n",
"qVOn/nbGjBnegQMHnk1NTT0yderUtTaPHHHBn/9v0k3e+g8ASvDGIgBQgqADgBIEHQCUIOgAoARB\n",
"BwAlCDoAKPH/nGmSIf1GtikAAAAASUVORK5CYII=\n"
],
"text/plain": [
"<matplotlib.figure.Figure at 0x10e588c10>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.hist()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ldi</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td> 209.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td> 0.420153</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td> 0.311662</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td> 0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td> 0.128000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td> 0.389000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td> 0.691000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td> 0.990000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ldi\n",
"count 209.000000\n",
"mean 0.420153\n",
"std 0.311662\n",
"min 0.000000\n",
"25% 0.128000\n",
"50% 0.389000\n",
"75% 0.691000\n",
"max 0.990000"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Click and drag to zoom, shift-click to pan, double click to autoscale."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~metasyn/27.embed\" height=\"525\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"py.iplot([Bar(x=df.country, y=df.ldi)])"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# LDI & GDP"
]
},
{
"cell_type": "code",
"execution_count": 256,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"gdp_data = \"\"\"1\t United States of America\t16,768,100\n",
"2\t China\t9,181,204\n",
"3\t Japan\t4,898,532\n",
"4\t Germany\t3,730,261\n",
"5\t France\t2,678,455\n",
"6\t United Kingdom\t2,267,456\n",
"7\t Brazil\t2,243,854\n",
"8\t Italy\t2,149,485\n",
"9\t Russia\t2,096,774\n",
"10\t India\t1,937,797\n",
"11\t Canada\t1,838,964\n",
"12\t Australia\t1,531,282\n",
"13\t Spain\t1,358,263\n",
"14\t South Korea\t1,304,554\n",
"15\t Mexico\t1,259,201\n",
"16\t Indonesia\t868,346\n",
"17\t Netherlands\t853,539\n",
"18\t Turkey\t822,149\n",
"19\t Saudi Arabia\t748,450\n",
"20\t Switzerland\t685,434\n",
"21\t Argentina\t611,726\n",
"22\t Sweden\t579,680\n",
"23\t Poland\t525,863\n",
"24\t Belgium\t524,806\n",
"25\t Norway\t522,349\n",
"26\t Nigeria\t514,965\n",
"27\t Iran\t492,783\n",
" Taiwan\t489,089\n",
"28\t Austria\t428,322\n",
"29\t Thailand\t420,167\n",
"30\t United Arab Emirates\t402,340\n",
"31\t Colombia\t378,148\n",
"32\t Venezuela\t371,339\n",
"33\t South Africa\t366,060\n",
"34\t Denmark\t336,701\n",
"35\t Malaysia\t312,434\n",
"36\t Singapore\t295,744\n",
"37\t Israel\t291,567\n",
"38\t Chile\t277,043\n",
" Hong Kong\t274,027\n",
"39\t Philippines\t272,067\n",
"40\t Finland\t267,329\n",
"41\t Egypt\t255,199\n",
"42\t Greece\t241,721\n",
"43\t Ireland\t232,077\n",
"44\t Portugal\t227,324\n",
"45\t Pakistan\t225,419\n",
"46\t Kazakhstan\t224,415\n",
"47\t Czech Republic\t208,796\n",
"48\t Algeria\t208,764\n",
"49\t Qatar\t202,450\n",
"50\t Peru\t200,269\n",
"51\t Iraq\t195,517\n",
"52\t New Zealand\t189,025\n",
"53\t Romania\t188,881\n",
"54\t Ukraine\t182,026\n",
"55\t Kuwait\t175,831\n",
"56\t Vietnam\t171,222\n",
"57\t Bangladesh\t153,505\n",
"58\t Hungary\t129,989\n",
"59\t Angola\t121,692\n",
" Puerto Rico\t105,149\n",
"60\t Morocco\t114,700\n",
"61\t Slovakia\t95,775\n",
"62\t Ecuador\t94,473\n",
"63\t Oman\t79,656\n",
"64\t Cuba\t78,694\n",
"65\t Libya\t74,597\n",
"66\t Azerbaijan\t73,557\n",
"67\t Belarus\t71,710\n",
"68\t Sri Lanka\t67,203\n",
"69\t Myanmar\t63,031\n",
"70\t Dominican Republic\t60,612\n",
"71\t Luxembourg\t60,131\n",
"72\t Croatia\t57,869\n",
"73\t Uzbekistan\t57,210\n",
"74\t Uruguay\t55,708\n",
"75\t Sudan\t54,595\n",
"76\t Bulgaria\t54,481\n",
"77\t Guatemala\t53,797\n",
" Macau\t51,753\n",
"78\t Costa Rica\t49,621\n",
"79\t Slovenia\t47,990\n",
"80\t Ghana\t47,830\n",
"81\t Lebanon\t47,221\n",
"82\t Tunisia\t46,883\n",
"83\t Lithuania\t46,403\n",
"84\t Ethiopia\t46,017\n",
"85\t Serbia\t45,520\n",
"86\t Kenya\t44,100\n",
"87\t Turkmenistan\t41,851\n",
"88\t Panama\t40,467\n",
"89\t Syria\t35,164\n",
"90\t Yemen\t34,714\n",
"91\t Jordan\t33,594\n",
"92\t Tanzania\t33,225\n",
"93\t Bahrain\t32,898\n",
"94\t Congo, Democratic Republic of the\t32,691\n",
"95\t Latvia\t30,953\n",
"96\t Bolivia\t30,601\n",
"97\t Cameroon\t29,568\n",
"98\t Paraguay\t29,208\n",
"99\t Cote d'Ivoire\t28,593\n",
"100\t Gabon\t24,076\n",
"101\t El Salvador\t23,864\n",
"102\t Trinidad and Tobago\t23,225\n",
"103\t Cyprus\t22,768\n",
"104\t Estonia\t22,376\n",
"105\t Uganda\t21,736\n",
"106\t Zambia\t21,490\n",
"107\t Afghanistan\t20,364\n",
"108\t Honduras\t18,564\n",
"109\t Nepal\t18,029\n",
"110\t Bosnia and Herzegovina\t17,319\n",
"111\t Brunei\t16,954\n",
"112\t Georgia\t15,830\n",
"113\t Papua New Guinea\t15,677\n",
"114\t Jamaica\t14,795\n",
"115\t Congo, Republic of the\t14,763\n",
"116\t Mozambique\t14,605\n",
"117\t Equatorial Guinea\t14,491\n",
"118\t North Korea\t14,411\n",
"119\t Botswana\t14,410\n",
"120\t Cambodia\t14,038\n",
"121\t Senegal\t13,962\n",
"122\t Iceland\t13,579\n",
"123\t Namibia\t12,807\n",
"124\t Albania\t12,044\n",
"125\t Mauritius\t11,452\n",
"126\t Burkina Faso\t10,687\n",
"127\t Nicaragua\t10,508\n",
"128\t Mongolia\t10,271\n",
"129\t Mali\t10,262\n",
" State of Palestine\t10,255\n",
"130\t Chad\t10,183\n",
"131\t South Sudan\t10,060\n",
"132\t Madagascar\t9,968\n",
"133\t Armenia\t9,950\n",
" New Caledonia\t9,840\n",
"134\t Zimbabwe\t9,802\n",
"135\t Macedonia, Republic of\t9,576\n",
"136\t Laos\t9,100\n",
"137\t Malta\t8,775\n",
"138\t Bahamas\t8,043\n",
"139\t Tajikistan\t7,633\n",
"140\t Benin\t7,557\n",
"141\t Moldova\t7,253\n",
"142\t Haiti\t7,187\n",
" French Polynesia\t7,150\n",
"143\t Rwanda\t7,103\n",
"144\t Niger\t6,773\n",
" Kosovo\t6,499\n",
"145\t Kyrgyzstan\t6,475\n",
"146\t Guinea\t6,092\n",
"147\t Liechtenstein\t5,827\n",
"148\t Monaco\t5,707\n",
"149\t Malawi\t5,653\n",
" Bermuda\t5,593\n",
"150\t Timor-Leste\t5,387\n",
"151\t Suriname\t5,012\n",
"152\t Barbados\t4,533\n",
"153\t Sierra Leone\t4,336\n",
"154\t Montenegro\t4,046\n",
" Netherlands Antilles\t4,009\n",
"155\t Fiji\t3,999\n",
"156\t Togo\t3,917\n",
"157\t Mauritania\t3,866\n",
"158\t Swaziland\t3,861\n",
" Cayman Islands\t3,393\n",
"159\t Andorra\t3,222\n",
"160\t Eritrea\t3,108\n",
"161\t Guyana\t2,851\n",
"162\t Maldives\t2,606\n",
" Aruba\t2,544\n",
"163\t Lesotho\t2,443\n",
" Greenland\t2,343\n",
"164\t Burundi\t2,257\n",
"165\t Central African Republic\t2,184\n",
"166\t Cape Verde\t1,903\n",
"167\t Bhutan\t1,861\n",
"168\t San Marino\t1,853\n",
"169\t Belize\t1,554\n",
"170\t Liberia\t1,491\n",
"171\t Djibouti\t1,361\n",
"172\t Saint Lucia\t1,318\n",
"173\t Somalia\t1,306\n",
"174\t Antigua and Barbuda\t1,176\n",
"175\t Seychelles\t1,031\n",
"176\t Solomon Islands\t1,010\n",
"177\t Gambia, The\t917\n",
" British Virgin Islands\t909\n",
"178\t Guinea-Bissau\t849\n",
"179\t Grenada\t783\n",
"180\t Saint Kitts and Nevis\t765\n",
" Zanzibar\t755\n",
"181\t Vanuatu\t752\n",
" Turks and Caicos Islands\t728\n",
"182\t Saint Vincent and the Grenadines\t694\n",
"183\t Samoa\t681\n",
"184\t Comoros\t616\n",
"185\t Dominica\t499\n",
"186\t Tonga\t465\n",
"187\t Micronesia, Federated States of\t327\n",
" Anguilla\t288\n",
" Cook Islands\t283\n",
"188\t Sao Tome and Principe\t261\n",
"189\t Palau\t213\n",
"190\t Marshall Islands\t198\n",
"191\t Kiribati\t176\n",
"192\t Nauru\t121\n",
" Montserrat\t64\n",
"193\t Tuvalu\t40\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 257,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"gdp_data = gdp_data[:-1] # get rid of last new line"
]
},
{
"cell_type": "code",
"execution_count": 258,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"clist = [t.split('\\t')[-2].decode('utf-8').strip() for t in gdp_data.split('\\n')]"
]
},
{
"cell_type": "code",
"execution_count": 259,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"gdplist = [int(t.split('\\t')[-1].replace(',','')) for t in gdp_data.split('\\n')]"
]
},
{
"cell_type": "code",
"execution_count": 260,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"gdp_df = pd.DataFrame()\n",
"gdp_df['gdp'] = gdplist\n",
"gdp_df['country'] = clist"
]
},
{
"cell_type": "code",
"execution_count": 261,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>gdp</th>\n",
" <th>country</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td> 16768100</td>\n",
" <td> United States of America</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td> 9181204</td>\n",
" <td> China</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td> 4898532</td>\n",
" <td> Japan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td> 3730261</td>\n",
" <td> Germany</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td> 2678455</td>\n",
" <td> France</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" gdp country\n",
"0 16768100 United States of America\n",
"1 9181204 China\n",
"2 4898532 Japan\n",
"3 3730261 Germany\n",
"4 2678455 France"
]
},
"execution_count": 261,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdp_df.head()"
]
},
{
"cell_type": "code",
"execution_count": 262,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mrgd = pd.merge(df, gdp_df, how='inner')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 264,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# normalized gdp\n",
"mrgd['n_gdp'] = (mrgd.gdp - min(mrgd.gdp)) / (max(mrgd.gdp) - min(mrgd.gdp))"
]
},
{
"cell_type": "code",
"execution_count": 265,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bar_ngdp = Bar(x=mrgd.country, y=mrgd.n_gdp, name=\"GDP\")\n",
"bar_ldi = Bar(x=mrgd.country, y=mrgd.ldi, name=\"LDI\")"
]
},
{
"cell_type": "code",
"execution_count": 266,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~metasyn/42.embed\" height=\"525\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"execution_count": 266,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"py.iplot({'data': [bar_ldi, bar_ngdp], 'layout': Layout(barmode='overlay', xaxis={'tickangle': 40}, margin={'b': 150})})"
]
},
{
"cell_type": "code",
"execution_count": 278,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Python/2.7/site-packages/pandas-0.15.0_93_ga0ac41d-py2.7-macosx-10.9-intel.egg/pandas/core/frame.py:1808: UserWarning:\n",
"\n",
"Boolean Series key will be reindexed to match DataFrame index.\n",
"\n"
]
}
],
"source": [
"sortd = mrgd.sort('n_gdp')[mrgd.n_gdp<.4]"
]
},
{
"cell_type": "code",
"execution_count": 279,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"bar_ngdp = Bar(x=sortd.country[10:], y=sortd.n_gdp[10:], name=\"GDP\")\n",
"bar_ldi = Bar(x=sortd.country[10:], y=sortd.ldi[10:], name=\"LDI\")"
]
},
{
"cell_type": "code",
"execution_count": 280,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Python/2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning:\n",
"\n",
"A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.\n",
"\n"
]
},
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\"seamless=\"seamless\" src=\"https://plot.ly/~metasyn/52.embed\" height=\"525\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"execution_count": 280,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"py.iplot({'data': [bar_ldi, bar_ngdp], 'layout': Layout(barmode='overlay', xaxis={'tickangle': 40}, margin={'b': 150})})"
]
},
{
"cell_type": "code",
"execution_count": 281,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ldi</th>\n",
" <th>gdp</th>\n",
" <th>n_gdp</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ldi</th>\n",
" <td> 1.000000</td>\n",
" <td>-0.104221</td>\n",
" <td>-0.104221</td>\n",
" </tr>\n",
" <tr>\n",
" <th>gdp</th>\n",
" <td>-0.104221</td>\n",
" <td> 1.000000</td>\n",
" <td> 1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>n_gdp</th>\n",
" <td>-0.104221</td>\n",
" <td> 1.000000</td>\n",
" <td> 1.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ldi gdp n_gdp\n",
"ldi 1.000000 -0.104221 -0.104221\n",
"gdp -0.104221 1.000000 1.000000\n",
"n_gdp -0.104221 1.000000 1.000000"
]
},
"execution_count": 281,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sortd.corr()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment