1
0
mirror of https://github.com/bspeice/kiva-dig synced 2024-12-04 20:58:09 -05:00
kiva-dig/Basic Prediction.ipynb
2016-12-03 10:06:50 -05:00

3727 lines
149 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from pyspark.sql import SQLContext\n",
"\n",
"LOCAL_PATH = 'file:///Users/Karl-Loic/Documents/Columbia-University/Fall-2016/Big-Data-Analytics/final-project/kiva-dig/'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sql_ctx = SQLContext(sc)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# TODO: Create permanent database tables for reuse\n",
"# Remove previously created metastore DB\n",
"import os, shutil\n",
"\n",
"if os.path.exists(LOCAL_PATH + 'metastore_db/'):\n",
" shutil.rmtree('metastore_db/')\n",
"loans = sql_ctx.read.json(LOCAL_PATH + 'kiva-data/loans.json')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1014130"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loans.count()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"root\n",
" |-- activity: string (nullable = true)\n",
" |-- basket_amount: long (nullable = true)\n",
" |-- bonus_credit_eligibility: boolean (nullable = true)\n",
" |-- borrowers: array (nullable = true)\n",
" | |-- element: struct (containsNull = true)\n",
" | | |-- first_name: string (nullable = true)\n",
" | | |-- gender: string (nullable = true)\n",
" | | |-- last_name: string (nullable = true)\n",
" | | |-- pictured: boolean (nullable = true)\n",
" |-- currency_exchange_loss_amount: double (nullable = true)\n",
" |-- delinquent: boolean (nullable = true)\n",
" |-- description: struct (nullable = true)\n",
" | |-- languages: array (nullable = true)\n",
" | | |-- element: string (containsNull = true)\n",
" | |-- texts: struct (nullable = true)\n",
" | | |-- ar: string (nullable = true)\n",
" | | |-- en: string (nullable = true)\n",
" | | |-- es: string (nullable = true)\n",
" | | |-- fr: string (nullable = true)\n",
" | | |-- id: string (nullable = true)\n",
" | | |-- mn: string (nullable = true)\n",
" | | |-- pt: string (nullable = true)\n",
" | | |-- ru: string (nullable = true)\n",
" | | |-- vi: string (nullable = true)\n",
" |-- funded_amount: long (nullable = true)\n",
" |-- funded_date: string (nullable = true)\n",
" |-- id: long (nullable = true)\n",
" |-- image: struct (nullable = true)\n",
" | |-- id: long (nullable = true)\n",
" | |-- template_id: long (nullable = true)\n",
" |-- journal_totals: struct (nullable = true)\n",
" | |-- bulkEntries: long (nullable = true)\n",
" | |-- entries: long (nullable = true)\n",
" |-- lender_count: long (nullable = true)\n",
" |-- loan_amount: long (nullable = true)\n",
" |-- location: struct (nullable = true)\n",
" | |-- country: string (nullable = true)\n",
" | |-- country_code: string (nullable = true)\n",
" | |-- geo: struct (nullable = true)\n",
" | | |-- level: string (nullable = true)\n",
" | | |-- pairs: string (nullable = true)\n",
" | | |-- type: string (nullable = true)\n",
" | |-- town: string (nullable = true)\n",
" |-- name: string (nullable = true)\n",
" |-- paid_amount: double (nullable = true)\n",
" |-- paid_date: string (nullable = true)\n",
" |-- partner_id: long (nullable = true)\n",
" |-- payments: array (nullable = true)\n",
" | |-- element: struct (containsNull = true)\n",
" | | |-- amount: double (nullable = true)\n",
" | | |-- currency_exchange_loss_amount: double (nullable = true)\n",
" | | |-- local_amount: double (nullable = true)\n",
" | | |-- payment_id: long (nullable = true)\n",
" | | |-- processed_date: string (nullable = true)\n",
" | | |-- rounded_local_amount: double (nullable = true)\n",
" | | |-- settlement_date: string (nullable = true)\n",
" |-- planned_expiration_date: string (nullable = true)\n",
" |-- posted_date: string (nullable = true)\n",
" |-- sector: string (nullable = true)\n",
" |-- status: string (nullable = true)\n",
" |-- tags: array (nullable = true)\n",
" | |-- element: struct (containsNull = true)\n",
" | | |-- name: string (nullable = true)\n",
" |-- terms: struct (nullable = true)\n",
" | |-- disbursal_amount: double (nullable = true)\n",
" | |-- disbursal_currency: string (nullable = true)\n",
" | |-- disbursal_date: string (nullable = true)\n",
" | |-- loan_amount: long (nullable = true)\n",
" | |-- local_payments: array (nullable = true)\n",
" | | |-- element: struct (containsNull = true)\n",
" | | | |-- amount: double (nullable = true)\n",
" | | | |-- due_date: string (nullable = true)\n",
" | |-- loss_liability: struct (nullable = true)\n",
" | | |-- currency_exchange: string (nullable = true)\n",
" | | |-- currency_exchange_coverage_rate: double (nullable = true)\n",
" | | |-- nonpayment: string (nullable = true)\n",
" | |-- repayment_interval: string (nullable = true)\n",
" | |-- repayment_term: long (nullable = true)\n",
" | |-- scheduled_payments: array (nullable = true)\n",
" | | |-- element: struct (containsNull = true)\n",
" | | | |-- amount: double (nullable = true)\n",
" | | | |-- due_date: string (nullable = true)\n",
" |-- themes: array (nullable = true)\n",
" | |-- element: string (containsNull = true)\n",
" |-- translator: struct (nullable = true)\n",
" | |-- byline: string (nullable = true)\n",
" | |-- image: long (nullable = true)\n",
" |-- use: string (nullable = true)\n",
" |-- video: struct (nullable = true)\n",
" | |-- id: long (nullable = true)\n",
" | |-- thumbnailImageId: long (nullable = true)\n",
" | |-- title: string (nullable = true)\n",
" | |-- youtubeId: string (nullable = true)\n",
"\n"
]
}
],
"source": [
"loans.printSchema()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[Row(activity=u'Clothing Sales', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=None, use=u'Compra de ropa dama, caballero y ni\\xf1o.', tags=[], status=u'deleted', delinquent=None),\n",
" Row(activity=u'Food Production/Sales', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-03-15T04:52:22Z', use=u'Working capital', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Food Production/Sales', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-05-17T22:02:42Z', use=u'Sell bread at the local market', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Clothing Sales', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-07-20T16:35:52Z', use=u'To buy more clothes and baby things for sale', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Livestock', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-09-20T02:55:18Z', use=u'Lohoure Odio will use the loan to purchase pigs for meat sales', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Construction', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-11-02T23:38:36Z', use=u'buy a welding machine', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Cereals', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2007-12-13T18:22:55Z', use=u'To buy rice for resale', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Taxi', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'1.0', disbursal_date=u'2008-01-11T20:44:52Z', use=u'Taxi repairs and repainting', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Used Clothing', basket_amount=None, num_borrowers=4, male_proportion(borrowers)=u'0.0', disbursal_date=u'2008-04-19T14:11:32Z', use=u'to invest in their businesses', tags=[], status=u'paid', delinquent=None),\n",
" Row(activity=u'Home Products Sales', basket_amount=None, num_borrowers=1, male_proportion(borrowers)=u'0.0', disbursal_date=u'2008-03-10T22:53:27Z', use=u'Edith needs a loan of 1000 soles (3 soles = $1), which she will use to buy more kitchen appliances.', tags=[], status=u'paid', delinquent=None)]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loans.registerTempTable(\"loans\")\n",
"\n",
"def male_proportion(borrowers):\n",
" num_males = 0\n",
" for item in borrowers:\n",
" if item.gender == 'M':\n",
" num_males += 1\n",
" \n",
" return num_males/ float(len(borrowers))\n",
"\n",
"sql_ctx.registerFunction('male_proportion', male_proportion)\n",
"\n",
"bad_loans = sql_ctx.sql(\"\"\"\n",
"SELECT \n",
" activity, \n",
" basket_amount,\n",
" size(borrowers) as num_borrowers,\n",
" male_proportion(borrowers),\n",
" terms.disbursal_date,\n",
" \n",
" use,\n",
" tags,\n",
" status,\n",
" delinquent\n",
"FROM loans\n",
"LIMIT 10\n",
"\"\"\")\n",
"\n",
"bad_loans.collect()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[Row(status=u'refunded', count(1)=5504),\n",
" Row(status=u'defaulted', count(1)=21776),\n",
" Row(status=u'in_repayment', count(1)=155748),\n",
" Row(status=u'reviewed', count(1)=3),\n",
" Row(status=u'deleted', count(1)=2722),\n",
" Row(status=u'paid', count(1)=775330),\n",
" Row(status=u'issue', count(1)=199),\n",
" Row(status=u'inactive_expired', count(1)=12421),\n",
" Row(status=u'fundraising', count(1)=3986),\n",
" Row(status=u'expired', count(1)=33773)]"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sql_ctx.sql(\"\"\"\n",
"SELECT\n",
" status,\n",
" COUNT(*)\n",
"FROM loans\n",
"GROUP BY status\n",
"LIMIT 10\n",
"\"\"\").collect()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Starts Here - GDP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Datasets sources\n",
"1. Country codes - https://github.com/datasets/country-codes/tree/master/data\n",
"2. GDP Data - http://data.worldbank.org/indicator/NY.GDP.MKTP.CD"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"from datetime import datetime\n",
"import numpy as np\n",
"import math\n",
"\n",
"\n",
"# Load country info data\n",
"country_codes_raw = pd.read_csv(LOCAL_PATH + 'economic-data/country-codes.csv')\n",
"country_gdp_raw = pd.read_csv(LOCAL_PATH + 'economic-data/country-gdp.csv')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"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>name</th>\n",
" <th>official_name_en</th>\n",
" <th>official_name_fr</th>\n",
" <th>ISO3166-1-Alpha-2</th>\n",
" <th>ISO3166-1-Alpha-3</th>\n",
" <th>ISO3166-1-numeric</th>\n",
" <th>ITU</th>\n",
" <th>MARC</th>\n",
" <th>WMO</th>\n",
" <th>DS</th>\n",
" <th>...</th>\n",
" <th>ISO4217-currency_minor_unit</th>\n",
" <th>ISO4217-currency_name</th>\n",
" <th>ISO4217-currency_numeric_code</th>\n",
" <th>is_independent</th>\n",
" <th>Capital</th>\n",
" <th>Continent</th>\n",
" <th>TLD</th>\n",
" <th>Languages</th>\n",
" <th>geonameid</th>\n",
" <th>EDGAR</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>NaN</td>\n",
" <td>Channel Islands</td>\n",
" <td>Îles Anglo-Normandes</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>830</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>NaN</td>\n",
" <td>Sark</td>\n",
" <td>Sercq</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>680</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Afghanistan</td>\n",
" <td>Afghanistan</td>\n",
" <td>Afghanistan</td>\n",
" <td>AF</td>\n",
" <td>AFG</td>\n",
" <td>4</td>\n",
" <td>AFG</td>\n",
" <td>af</td>\n",
" <td>AF</td>\n",
" <td>AFG</td>\n",
" <td>...</td>\n",
" <td>2.0</td>\n",
" <td>Afghani</td>\n",
" <td>971.0</td>\n",
" <td>Yes</td>\n",
" <td>Kabul</td>\n",
" <td>AS</td>\n",
" <td>.af</td>\n",
" <td>fa-AF,ps,uz-AF,tk</td>\n",
" <td>1149361.0</td>\n",
" <td>B2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Albania</td>\n",
" <td>Albania</td>\n",
" <td>Albanie</td>\n",
" <td>AL</td>\n",
" <td>ALB</td>\n",
" <td>8</td>\n",
" <td>ALB</td>\n",
" <td>aa</td>\n",
" <td>AB</td>\n",
" <td>AL</td>\n",
" <td>...</td>\n",
" <td>2.0</td>\n",
" <td>Lek</td>\n",
" <td>8.0</td>\n",
" <td>Yes</td>\n",
" <td>Tirana</td>\n",
" <td>EU</td>\n",
" <td>.al</td>\n",
" <td>sq,el</td>\n",
" <td>783754.0</td>\n",
" <td>B3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Algeria</td>\n",
" <td>Algeria</td>\n",
" <td>Algérie</td>\n",
" <td>DZ</td>\n",
" <td>DZA</td>\n",
" <td>12</td>\n",
" <td>ALG</td>\n",
" <td>ae</td>\n",
" <td>AL</td>\n",
" <td>DZ</td>\n",
" <td>...</td>\n",
" <td>2.0</td>\n",
" <td>Algerian Dinar</td>\n",
" <td>12.0</td>\n",
" <td>Yes</td>\n",
" <td>Algiers</td>\n",
" <td>AF</td>\n",
" <td>.dz</td>\n",
" <td>ar-DZ</td>\n",
" <td>2589581.0</td>\n",
" <td>B4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 27 columns</p>\n",
"</div>"
],
"text/plain": [
" name official_name_en official_name_fr ISO3166-1-Alpha-2 \\\n",
"0 NaN Channel Islands Îles Anglo-Normandes NaN \n",
"1 NaN Sark Sercq NaN \n",
"2 Afghanistan Afghanistan Afghanistan AF \n",
"3 Albania Albania Albanie AL \n",
"4 Algeria Algeria Algérie DZ \n",
"\n",
" ISO3166-1-Alpha-3 ISO3166-1-numeric ITU MARC WMO DS ... \\\n",
"0 NaN 830 NaN NaN NaN NaN ... \n",
"1 NaN 680 NaN NaN NaN NaN ... \n",
"2 AFG 4 AFG af AF AFG ... \n",
"3 ALB 8 ALB aa AB AL ... \n",
"4 DZA 12 ALG ae AL DZ ... \n",
"\n",
" ISO4217-currency_minor_unit ISO4217-currency_name \\\n",
"0 NaN NaN \n",
"1 NaN NaN \n",
"2 2.0 Afghani \n",
"3 2.0 Lek \n",
"4 2.0 Algerian Dinar \n",
"\n",
" ISO4217-currency_numeric_code is_independent Capital Continent TLD \\\n",
"0 NaN NaN NaN NaN NaN \n",
"1 NaN NaN NaN NaN NaN \n",
"2 971.0 Yes Kabul AS .af \n",
"3 8.0 Yes Tirana EU .al \n",
"4 12.0 Yes Algiers AF .dz \n",
"\n",
" Languages geonameid EDGAR \n",
"0 NaN NaN NaN \n",
"1 NaN NaN NaN \n",
"2 fa-AF,ps,uz-AF,tk 1149361.0 B2 \n",
"3 sq,el 783754.0 B3 \n",
"4 ar-DZ 2589581.0 B4 \n",
"\n",
"[5 rows x 27 columns]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_codes_raw.head()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>Series Name</th>\n",
" <th>Series Code</th>\n",
" <th>Country Name</th>\n",
" <th>Country Code</th>\n",
" <th>2002 [YR2002]</th>\n",
" <th>2003 [YR2003]</th>\n",
" <th>2004 [YR2004]</th>\n",
" <th>2005 [YR2005]</th>\n",
" <th>2006 [YR2006]</th>\n",
" <th>2007 [YR2007]</th>\n",
" <th>2008 [YR2008]</th>\n",
" <th>2009 [YR2009]</th>\n",
" <th>2010 [YR2010]</th>\n",
" <th>2011 [YR2011]</th>\n",
" <th>2012 [YR2012]</th>\n",
" <th>2013 [YR2013]</th>\n",
" <th>2014 [YR2014]</th>\n",
" <th>2015 [YR2015]</th>\n",
" <th>2016 [YR2016]</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>GDP per capita (current US$)</td>\n",
" <td>NY.GDP.PCAP.CD</td>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>192.153528278789</td>\n",
" <td>203.651040923182</td>\n",
" <td>224.914712193371</td>\n",
" <td>257.175794656273</td>\n",
" <td>280.245644106914</td>\n",
" <td>380.400955186598</td>\n",
" <td>384.131681276838</td>\n",
" <td>458.955781585831</td>\n",
" <td>569.940728793286</td>\n",
" <td>622.379654358451</td>\n",
" <td>690.842629014956</td>\n",
" <td>653.347488111011</td>\n",
" <td>633.947864294639</td>\n",
" <td>590.269515382605</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>GDP per capita (current US$)</td>\n",
" <td>NY.GDP.PCAP.CD</td>\n",
" <td>Albania</td>\n",
" <td>ALB</td>\n",
" <td>1453.64277660853</td>\n",
" <td>1890.68155743544</td>\n",
" <td>2416.5882350701</td>\n",
" <td>2709.14293056201</td>\n",
" <td>3005.0129033756</td>\n",
" <td>3603.01368536638</td>\n",
" <td>4370.53964653148</td>\n",
" <td>4114.13654490945</td>\n",
" <td>4094.35883191918</td>\n",
" <td>4437.8119990258</td>\n",
" <td>4247.83985201907</td>\n",
" <td>4412.34557813421</td>\n",
" <td>4588.64944014811</td>\n",
" <td>3965.01680558488</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>GDP per capita (current US$)</td>\n",
" <td>NY.GDP.PCAP.CD</td>\n",
" <td>Algeria</td>\n",
" <td>DZA</td>\n",
" <td>1774.29202079911</td>\n",
" <td>2094.89330213298</td>\n",
" <td>2600.00651972559</td>\n",
" <td>3102.03738422673</td>\n",
" <td>3467.54474008596</td>\n",
" <td>3939.55993939808</td>\n",
" <td>4912.25194081995</td>\n",
" <td>3875.82209542426</td>\n",
" <td>4473.48644568115</td>\n",
" <td>5447.40397556569</td>\n",
" <td>5583.61615950131</td>\n",
" <td>5491.6144135648</td>\n",
" <td>5484.0668056148</td>\n",
" <td>4206.03123244958</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>GDP per capita (current US$)</td>\n",
" <td>NY.GDP.PCAP.CD</td>\n",
" <td>American Samoa</td>\n",
" <td>ASM</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>GDP per capita (current US$)</td>\n",
" <td>NY.GDP.PCAP.CD</td>\n",
" <td>Andorra</td>\n",
" <td>ADO</td>\n",
" <td>24175.3727542522</td>\n",
" <td>31742.9925847537</td>\n",
" <td>37235.4500323146</td>\n",
" <td>39990.3304085679</td>\n",
" <td>42417.2291456984</td>\n",
" <td>47253.5297963111</td>\n",
" <td>46735.9995745016</td>\n",
" <td>42701.447136255</td>\n",
" <td>39639.386021211</td>\n",
" <td>41630.0525792977</td>\n",
" <td>39666.3692147448</td>\n",
" <td>42806.5224483021</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Series Name Series Code Country Name Country Code \\\n",
"0 GDP per capita (current US$) NY.GDP.PCAP.CD Afghanistan AFG \n",
"1 GDP per capita (current US$) NY.GDP.PCAP.CD Albania ALB \n",
"2 GDP per capita (current US$) NY.GDP.PCAP.CD Algeria DZA \n",
"3 GDP per capita (current US$) NY.GDP.PCAP.CD American Samoa ASM \n",
"4 GDP per capita (current US$) NY.GDP.PCAP.CD Andorra ADO \n",
"\n",
" 2002 [YR2002] 2003 [YR2003] 2004 [YR2004] 2005 [YR2005] \\\n",
"0 192.153528278789 203.651040923182 224.914712193371 257.175794656273 \n",
"1 1453.64277660853 1890.68155743544 2416.5882350701 2709.14293056201 \n",
"2 1774.29202079911 2094.89330213298 2600.00651972559 3102.03738422673 \n",
"3 .. .. .. .. \n",
"4 24175.3727542522 31742.9925847537 37235.4500323146 39990.3304085679 \n",
"\n",
" 2006 [YR2006] 2007 [YR2007] 2008 [YR2008] 2009 [YR2009] \\\n",
"0 280.245644106914 380.400955186598 384.131681276838 458.955781585831 \n",
"1 3005.0129033756 3603.01368536638 4370.53964653148 4114.13654490945 \n",
"2 3467.54474008596 3939.55993939808 4912.25194081995 3875.82209542426 \n",
"3 .. .. .. .. \n",
"4 42417.2291456984 47253.5297963111 46735.9995745016 42701.447136255 \n",
"\n",
" 2010 [YR2010] 2011 [YR2011] 2012 [YR2012] 2013 [YR2013] \\\n",
"0 569.940728793286 622.379654358451 690.842629014956 653.347488111011 \n",
"1 4094.35883191918 4437.8119990258 4247.83985201907 4412.34557813421 \n",
"2 4473.48644568115 5447.40397556569 5583.61615950131 5491.6144135648 \n",
"3 .. .. .. .. \n",
"4 39639.386021211 41630.0525792977 39666.3692147448 42806.5224483021 \n",
"\n",
" 2014 [YR2014] 2015 [YR2015] 2016 [YR2016] \n",
"0 633.947864294639 590.269515382605 .. \n",
"1 4588.64944014811 3965.01680558488 .. \n",
"2 5484.0668056148 4206.03123244958 .. \n",
"3 .. .. .. \n",
"4 .. .. .. "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_gdp_raw.head()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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>official_name_en</th>\n",
" <th>ISO3166-1-Alpha-2</th>\n",
" <th>ISO3166-1-Alpha-3</th>\n",
" <th>ISO4217-currency_alphabetic_code</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Channel Islands</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Sark</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Afghanistan</td>\n",
" <td>AF</td>\n",
" <td>AFG</td>\n",
" <td>AFN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Albania</td>\n",
" <td>AL</td>\n",
" <td>ALB</td>\n",
" <td>ALL</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Algeria</td>\n",
" <td>DZ</td>\n",
" <td>DZA</td>\n",
" <td>DZD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>American Samoa</td>\n",
" <td>AS</td>\n",
" <td>ASM</td>\n",
" <td>USD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Andorra</td>\n",
" <td>AD</td>\n",
" <td>AND</td>\n",
" <td>EUR</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Angola</td>\n",
" <td>AO</td>\n",
" <td>AGO</td>\n",
" <td>AOA</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Anguilla</td>\n",
" <td>AI</td>\n",
" <td>AIA</td>\n",
" <td>XCD</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>NaN</td>\n",
" <td>AQ</td>\n",
" <td>ATA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" official_name_en ISO3166-1-Alpha-2 ISO3166-1-Alpha-3 \\\n",
"0 Channel Islands NaN NaN \n",
"1 Sark NaN NaN \n",
"2 Afghanistan AF AFG \n",
"3 Albania AL ALB \n",
"4 Algeria DZ DZA \n",
"5 American Samoa AS ASM \n",
"6 Andorra AD AND \n",
"7 Angola AO AGO \n",
"8 Anguilla AI AIA \n",
"9 NaN AQ ATA \n",
"\n",
" ISO4217-currency_alphabetic_code \n",
"0 NaN \n",
"1 NaN \n",
"2 AFN \n",
"3 ALL \n",
"4 DZD \n",
"5 USD \n",
"6 EUR \n",
"7 AOA \n",
"8 XCD \n",
"9 NaN "
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Clean country codes data\n",
"country_codes = country_codes_raw[['official_name_en', 'ISO3166-1-Alpha-2', 'ISO3166-1-Alpha-3', 'ISO4217-currency_alphabetic_code']]\n",
"country_codes.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Clean gdp data\n",
"country_gdp = country_gdp_raw.drop(country_gdp_raw.columns[[0, 1]], axis=1)\n",
"country_gdp.columns = ['name', 'country_code_3', '2002', '2003', '2004', '2005', '2006',\n",
" '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016']"
]
},
{
"cell_type": "code",
"execution_count": 19,
"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>name</th>\n",
" <th>country_code_3</th>\n",
" <th>2002</th>\n",
" <th>2003</th>\n",
" <th>2004</th>\n",
" <th>2005</th>\n",
" <th>2006</th>\n",
" <th>2007</th>\n",
" <th>2008</th>\n",
" <th>2009</th>\n",
" <th>2010</th>\n",
" <th>2011</th>\n",
" <th>2012</th>\n",
" <th>2013</th>\n",
" <th>2014</th>\n",
" <th>2015</th>\n",
" <th>2016</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Afghanistan</td>\n",
" <td>AFG</td>\n",
" <td>192.153528278789</td>\n",
" <td>203.651040923182</td>\n",
" <td>224.914712193371</td>\n",
" <td>257.175794656273</td>\n",
" <td>280.245644106914</td>\n",
" <td>380.400955186598</td>\n",
" <td>384.131681276838</td>\n",
" <td>458.955781585831</td>\n",
" <td>569.940728793286</td>\n",
" <td>622.379654358451</td>\n",
" <td>690.842629014956</td>\n",
" <td>653.347488111011</td>\n",
" <td>633.947864294639</td>\n",
" <td>590.269515382605</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Albania</td>\n",
" <td>ALB</td>\n",
" <td>1453.64277660853</td>\n",
" <td>1890.68155743544</td>\n",
" <td>2416.5882350701</td>\n",
" <td>2709.14293056201</td>\n",
" <td>3005.0129033756</td>\n",
" <td>3603.01368536638</td>\n",
" <td>4370.53964653148</td>\n",
" <td>4114.13654490945</td>\n",
" <td>4094.35883191918</td>\n",
" <td>4437.8119990258</td>\n",
" <td>4247.83985201907</td>\n",
" <td>4412.34557813421</td>\n",
" <td>4588.64944014811</td>\n",
" <td>3965.01680558488</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Algeria</td>\n",
" <td>DZA</td>\n",
" <td>1774.29202079911</td>\n",
" <td>2094.89330213298</td>\n",
" <td>2600.00651972559</td>\n",
" <td>3102.03738422673</td>\n",
" <td>3467.54474008596</td>\n",
" <td>3939.55993939808</td>\n",
" <td>4912.25194081995</td>\n",
" <td>3875.82209542426</td>\n",
" <td>4473.48644568115</td>\n",
" <td>5447.40397556569</td>\n",
" <td>5583.61615950131</td>\n",
" <td>5491.6144135648</td>\n",
" <td>5484.0668056148</td>\n",
" <td>4206.03123244958</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>American Samoa</td>\n",
" <td>ASM</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Andorra</td>\n",
" <td>ADO</td>\n",
" <td>24175.3727542522</td>\n",
" <td>31742.9925847537</td>\n",
" <td>37235.4500323146</td>\n",
" <td>39990.3304085679</td>\n",
" <td>42417.2291456984</td>\n",
" <td>47253.5297963111</td>\n",
" <td>46735.9995745016</td>\n",
" <td>42701.447136255</td>\n",
" <td>39639.386021211</td>\n",
" <td>41630.0525792977</td>\n",
" <td>39666.3692147448</td>\n",
" <td>42806.5224483021</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name country_code_3 2002 2003 \\\n",
"0 Afghanistan AFG 192.153528278789 203.651040923182 \n",
"1 Albania ALB 1453.64277660853 1890.68155743544 \n",
"2 Algeria DZA 1774.29202079911 2094.89330213298 \n",
"3 American Samoa ASM .. .. \n",
"4 Andorra ADO 24175.3727542522 31742.9925847537 \n",
"\n",
" 2004 2005 2006 2007 \\\n",
"0 224.914712193371 257.175794656273 280.245644106914 380.400955186598 \n",
"1 2416.5882350701 2709.14293056201 3005.0129033756 3603.01368536638 \n",
"2 2600.00651972559 3102.03738422673 3467.54474008596 3939.55993939808 \n",
"3 .. .. .. .. \n",
"4 37235.4500323146 39990.3304085679 42417.2291456984 47253.5297963111 \n",
"\n",
" 2008 2009 2010 2011 \\\n",
"0 384.131681276838 458.955781585831 569.940728793286 622.379654358451 \n",
"1 4370.53964653148 4114.13654490945 4094.35883191918 4437.8119990258 \n",
"2 4912.25194081995 3875.82209542426 4473.48644568115 5447.40397556569 \n",
"3 .. .. .. .. \n",
"4 46735.9995745016 42701.447136255 39639.386021211 41630.0525792977 \n",
"\n",
" 2012 2013 2014 2015 2016 \n",
"0 690.842629014956 653.347488111011 633.947864294639 590.269515382605 .. \n",
"1 4247.83985201907 4412.34557813421 4588.64944014811 3965.01680558488 .. \n",
"2 5583.61615950131 5491.6144135648 5484.0668056148 4206.03123244958 .. \n",
"3 .. .. .. .. .. \n",
"4 39666.3692147448 42806.5224483021 .. .. .. "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_gdp.head()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"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>name</th>\n",
" <th>country_code</th>\n",
" <th>currency_code</th>\n",
" <th>2002</th>\n",
" <th>2003</th>\n",
" <th>2004</th>\n",
" <th>2005</th>\n",
" <th>2006</th>\n",
" <th>2007</th>\n",
" <th>2008</th>\n",
" <th>2009</th>\n",
" <th>2010</th>\n",
" <th>2011</th>\n",
" <th>2012</th>\n",
" <th>2013</th>\n",
" <th>2014</th>\n",
" <th>2015</th>\n",
" <th>2016</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Afghanistan</td>\n",
" <td>AF</td>\n",
" <td>AFN</td>\n",
" <td>192.153528278789</td>\n",
" <td>203.651040923182</td>\n",
" <td>224.914712193371</td>\n",
" <td>257.175794656273</td>\n",
" <td>280.245644106914</td>\n",
" <td>380.400955186598</td>\n",
" <td>384.131681276838</td>\n",
" <td>458.955781585831</td>\n",
" <td>569.940728793286</td>\n",
" <td>622.379654358451</td>\n",
" <td>690.842629014956</td>\n",
" <td>653.347488111011</td>\n",
" <td>633.947864294639</td>\n",
" <td>590.269515382605</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Albania</td>\n",
" <td>AL</td>\n",
" <td>ALL</td>\n",
" <td>1453.64277660853</td>\n",
" <td>1890.68155743544</td>\n",
" <td>2416.5882350701</td>\n",
" <td>2709.14293056201</td>\n",
" <td>3005.0129033756</td>\n",
" <td>3603.01368536638</td>\n",
" <td>4370.53964653148</td>\n",
" <td>4114.13654490945</td>\n",
" <td>4094.35883191918</td>\n",
" <td>4437.8119990258</td>\n",
" <td>4247.83985201907</td>\n",
" <td>4412.34557813421</td>\n",
" <td>4588.64944014811</td>\n",
" <td>3965.01680558488</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Algeria</td>\n",
" <td>DZ</td>\n",
" <td>DZD</td>\n",
" <td>1774.29202079911</td>\n",
" <td>2094.89330213298</td>\n",
" <td>2600.00651972559</td>\n",
" <td>3102.03738422673</td>\n",
" <td>3467.54474008596</td>\n",
" <td>3939.55993939808</td>\n",
" <td>4912.25194081995</td>\n",
" <td>3875.82209542426</td>\n",
" <td>4473.48644568115</td>\n",
" <td>5447.40397556569</td>\n",
" <td>5583.61615950131</td>\n",
" <td>5491.6144135648</td>\n",
" <td>5484.0668056148</td>\n",
" <td>4206.03123244958</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>American Samoa</td>\n",
" <td>AS</td>\n",
" <td>USD</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Andorra</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>24175.3727542522</td>\n",
" <td>31742.9925847537</td>\n",
" <td>37235.4500323146</td>\n",
" <td>39990.3304085679</td>\n",
" <td>42417.2291456984</td>\n",
" <td>47253.5297963111</td>\n",
" <td>46735.9995745016</td>\n",
" <td>42701.447136255</td>\n",
" <td>39639.386021211</td>\n",
" <td>41630.0525792977</td>\n",
" <td>39666.3692147448</td>\n",
" <td>42806.5224483021</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Angola</td>\n",
" <td>AO</td>\n",
" <td>AOA</td>\n",
" <td>775.765518459716</td>\n",
" <td>850.075694129697</td>\n",
" <td>1135.60456355085</td>\n",
" <td>1576.16280066689</td>\n",
" <td>2253.83885003865</td>\n",
" <td>3151.02243105289</td>\n",
" <td>4242.36306234092</td>\n",
" <td>3678.94765447179</td>\n",
" <td>3886.47935432524</td>\n",
" <td>4744.98762949589</td>\n",
" <td>5086.8484258086</td>\n",
" <td>5327.14889219232</td>\n",
" <td>5232.69050054132</td>\n",
" <td>4102.11858969272</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Antigua and Barbuda</td>\n",
" <td>AG</td>\n",
" <td>XCD</td>\n",
" <td>10027.8562205839</td>\n",
" <td>10382.6309004545</td>\n",
" <td>10993.3692472668</td>\n",
" <td>12079.8656950416</td>\n",
" <td>13599.908857304</td>\n",
" <td>15276.0682646698</td>\n",
" <td>15786.1728395062</td>\n",
" <td>13979.2626925883</td>\n",
" <td>13017.3103875487</td>\n",
" <td>12817.8415733094</td>\n",
" <td>13525.616220134</td>\n",
" <td>13342.0849977054</td>\n",
" <td>13432.0792079208</td>\n",
" <td>14128.8785463675</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Argentina</td>\n",
" <td>AR</td>\n",
" <td>ARS</td>\n",
" <td>2579.18819898884</td>\n",
" <td>3330.42866006847</td>\n",
" <td>4251.5653466058</td>\n",
" <td>5096.25833247505</td>\n",
" <td>5904.67813228342</td>\n",
" <td>7226.27029452745</td>\n",
" <td>8992.58961919674</td>\n",
" <td>8198.56611136286</td>\n",
" <td>10332.0323662966</td>\n",
" <td>12800.2018563295</td>\n",
" <td>13040.306395228</td>\n",
" <td>13027.2048221392</td>\n",
" <td>12324.9387857728</td>\n",
" <td>13431.8783398577</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Armenia</td>\n",
" <td>AM</td>\n",
" <td>AMD</td>\n",
" <td>779.829626131555</td>\n",
" <td>924.464009817761</td>\n",
" <td>1181.9684454224</td>\n",
" <td>1625.40776912682</td>\n",
" <td>2126.61866107184</td>\n",
" <td>3080.97095943572</td>\n",
" <td>3919.97547381061</td>\n",
" <td>2915.5839059087</td>\n",
" <td>3124.78401786195</td>\n",
" <td>3417.17183599915</td>\n",
" <td>3565.5175749254</td>\n",
" <td>3716.82892254464</td>\n",
" <td>3873.53356580682</td>\n",
" <td>3499.80421759862</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Aruba</td>\n",
" <td>AW</td>\n",
" <td>AWG</td>\n",
" <td>20433.6541088167</td>\n",
" <td>20834.9397101237</td>\n",
" <td>22566.6821576324</td>\n",
" <td>23302.8319880055</td>\n",
" <td>24015.4206122701</td>\n",
" <td>25921.5382341406</td>\n",
" <td>27549.8894224976</td>\n",
" <td>24640.4212441218</td>\n",
" <td>24289.1415161326</td>\n",
" <td>25353.7875446441</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Australia</td>\n",
" <td>AU</td>\n",
" <td>AUD</td>\n",
" <td>20059.4520721372</td>\n",
" <td>23440.0053221856</td>\n",
" <td>30440.8548786229</td>\n",
" <td>33982.9504271591</td>\n",
" <td>36084.8589777475</td>\n",
" <td>40957.8304392487</td>\n",
" <td>49628.1151270179</td>\n",
" <td>42715.1322619629</td>\n",
" <td>51845.6548605562</td>\n",
" <td>62216.5471294133</td>\n",
" <td>67646.1038529626</td>\n",
" <td>67652.6832146189</td>\n",
" <td>61995.8296976</td>\n",
" <td>56327.7214484289</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>Austria</td>\n",
" <td>AT</td>\n",
" <td>EUR</td>\n",
" <td>26351.3756769542</td>\n",
" <td>32102.9305523558</td>\n",
" <td>36693.4026205182</td>\n",
" <td>38242.0425174699</td>\n",
" <td>40430.993614499</td>\n",
" <td>46586.6502529235</td>\n",
" <td>51386.3766511975</td>\n",
" <td>47654.1872090808</td>\n",
" <td>46659.8408181344</td>\n",
" <td>51123.5613291663</td>\n",
" <td>48324.2540367606</td>\n",
" <td>50557.8038059874</td>\n",
" <td>51148.3588760796</td>\n",
" <td>43438.8630381343</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Azerbaijan</td>\n",
" <td>AZ</td>\n",
" <td>AZN</td>\n",
" <td>763.101212220367</td>\n",
" <td>883.614008967961</td>\n",
" <td>1045.02641527642</td>\n",
" <td>1578.36733030667</td>\n",
" <td>2473.08577636837</td>\n",
" <td>3851.43786871172</td>\n",
" <td>5574.60380218613</td>\n",
" <td>4950.29479142375</td>\n",
" <td>5842.80578358576</td>\n",
" <td>7189.69122920765</td>\n",
" <td>7393.77187697623</td>\n",
" <td>7811.6214184582</td>\n",
" <td>7886.45914367274</td>\n",
" <td>5496.34464026248</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Bahamas, The</td>\n",
" <td>BS</td>\n",
" <td>BSD</td>\n",
" <td>22505.4047934793</td>\n",
" <td>22008.4337005989</td>\n",
" <td>21995.5199216219</td>\n",
" <td>23405.8795479327</td>\n",
" <td>23721.1562800587</td>\n",
" <td>24306.1424243044</td>\n",
" <td>23657.365306222</td>\n",
" <td>22043.0125711709</td>\n",
" <td>21920.5165867583</td>\n",
" <td>21514.8986531628</td>\n",
" <td>22112.6083547268</td>\n",
" <td>22315.6036533886</td>\n",
" <td>22217.4941392075</td>\n",
" <td>22896.9236868716</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>Bahrain</td>\n",
" <td>BH</td>\n",
" <td>BHD</td>\n",
" <td>13279.0457951397</td>\n",
" <td>14541.6160485141</td>\n",
" <td>16275.1804236433</td>\n",
" <td>18418.0726743768</td>\n",
" <td>19669.3195545631</td>\n",
" <td>21167.6187062133</td>\n",
" <td>23043.0253174017</td>\n",
" <td>19166.7082382358</td>\n",
" <td>20386.0175551116</td>\n",
" <td>22238.7119502059</td>\n",
" <td>23063.1322870426</td>\n",
" <td>24378.9448284188</td>\n",
" <td>24855.2156350086</td>\n",
" <td>23395.7476902684</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>Bangladesh</td>\n",
" <td>BD</td>\n",
" <td>BDT</td>\n",
" <td>401.708153328187</td>\n",
" <td>434.046563233432</td>\n",
" <td>462.274879844841</td>\n",
" <td>485.852888073473</td>\n",
" <td>495.853780201055</td>\n",
" <td>543.082263122362</td>\n",
" <td>618.075883559283</td>\n",
" <td>683.614422272329</td>\n",
" <td>760.331935200195</td>\n",
" <td>838.547801702232</td>\n",
" <td>858.933362587621</td>\n",
" <td>954.396399715624</td>\n",
" <td>1086.80008676935</td>\n",
" <td>1211.70153057661</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>Barbados</td>\n",
" <td>BB</td>\n",
" <td>BBD</td>\n",
" <td>11674.9361829092</td>\n",
" <td>12028.8987405468</td>\n",
" <td>12869.3365947615</td>\n",
" <td>14223.7777039775</td>\n",
" <td>15646.815008726</td>\n",
" <td>16461.8292691759</td>\n",
" <td>16569.6049618665</td>\n",
" <td>16526.2545517227</td>\n",
" <td>15901.4329353355</td>\n",
" <td>15530.8942915589</td>\n",
" <td>15317.1390013495</td>\n",
" <td>15153.8213753482</td>\n",
" <td>15366.2926106288</td>\n",
" <td>15660.6794152314</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>Belarus</td>\n",
" <td>BY</td>\n",
" <td>BYR</td>\n",
" <td>1479.46532113219</td>\n",
" <td>1819.4790277163</td>\n",
" <td>2378.37489391196</td>\n",
" <td>3126.36777779462</td>\n",
" <td>3848.58620300891</td>\n",
" <td>4735.95688918873</td>\n",
" <td>6376.17311491284</td>\n",
" <td>5176.04470138203</td>\n",
" <td>5818.8548592158</td>\n",
" <td>6305.77366247653</td>\n",
" <td>6721.83490773968</td>\n",
" <td>7722.12335060436</td>\n",
" <td>8025.30435552468</td>\n",
" <td>5740.45649479562</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>Belgium</td>\n",
" <td>BE</td>\n",
" <td>EUR</td>\n",
" <td>25052.3302823</td>\n",
" <td>30743.9569254283</td>\n",
" <td>35589.7129457001</td>\n",
" <td>36967.2829204297</td>\n",
" <td>38852.3610339939</td>\n",
" <td>44403.8313061102</td>\n",
" <td>48424.5892730273</td>\n",
" <td>44880.5601517887</td>\n",
" <td>44382.8797683492</td>\n",
" <td>47699.8070518961</td>\n",
" <td>44734.4523465803</td>\n",
" <td>46622.4679873931</td>\n",
" <td>47299.8601085612</td>\n",
" <td>40231.2831740081</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>Belize</td>\n",
" <td>BZ</td>\n",
" <td>BZD</td>\n",
" <td>3556.61608225719</td>\n",
" <td>3679.79281542143</td>\n",
" <td>3831.60983030588</td>\n",
" <td>3933.2343731798</td>\n",
" <td>4187.23288999866</td>\n",
" <td>4324.83101711444</td>\n",
" <td>4470.22079597603</td>\n",
" <td>4258.84287648324</td>\n",
" <td>4344.13666906088</td>\n",
" <td>4516.23303047149</td>\n",
" <td>4673.55519784264</td>\n",
" <td>4723.59432062825</td>\n",
" <td>4884.3686203818</td>\n",
" <td>4906.9406908683</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>Benin</td>\n",
" <td>BJ</td>\n",
" <td>XOF</td>\n",
" <td>411.959075281789</td>\n",
" <td>509.461088697817</td>\n",
" <td>570.685501333771</td>\n",
" <td>587.080212422838</td>\n",
" <td>609.018608681583</td>\n",
" <td>685.551675107742</td>\n",
" <td>794.870176064085</td>\n",
" <td>768.013476447657</td>\n",
" <td>732.953622726674</td>\n",
" <td>799.03555913143</td>\n",
" <td>807.688451017232</td>\n",
" <td>882.638633279988</td>\n",
" <td>903.464924007693</td>\n",
" <td>779.067867757338</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>Bermuda</td>\n",
" <td>BM</td>\n",
" <td>BMD</td>\n",
" <td>62583.1002034588</td>\n",
" <td>66111.7252270036</td>\n",
" <td>70359.3191088798</td>\n",
" <td>75882.0338560339</td>\n",
" <td>83912.6977976846</td>\n",
" <td>90849.5869806436</td>\n",
" <td>93605.7481653976</td>\n",
" <td>88463.3128161375</td>\n",
" <td>88207.3275597322</td>\n",
" <td>85973.158416455</td>\n",
" <td>85458.455507886</td>\n",
" <td>85748.0654143782</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>Bhutan</td>\n",
" <td>BT</td>\n",
" <td>INR</td>\n",
" <td>897.445333164014</td>\n",
" <td>1009.00623184688</td>\n",
" <td>1107.92059564068</td>\n",
" <td>1257.54864008661</td>\n",
" <td>1346.08577480046</td>\n",
" <td>1755.16170904287</td>\n",
" <td>1810.57617704401</td>\n",
" <td>1786.81067200588</td>\n",
" <td>2201.29307778936</td>\n",
" <td>2485.78705216849</td>\n",
" <td>2452.15158793741</td>\n",
" <td>2383.04472990264</td>\n",
" <td>2560.52213174131</td>\n",
" <td>2532.45446832741</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>Bolivia</td>\n",
" <td>BO</td>\n",
" <td>BOB</td>\n",
" <td>913.575853422027</td>\n",
" <td>917.36431048617</td>\n",
" <td>978.334757576746</td>\n",
" <td>1046.4278428307</td>\n",
" <td>1233.59297372996</td>\n",
" <td>1389.6317502607</td>\n",
" <td>1736.92401415151</td>\n",
" <td>1776.85718962366</td>\n",
" <td>1981.16010525701</td>\n",
" <td>2377.70068972888</td>\n",
" <td>2645.29027433174</td>\n",
" <td>2948.03291763073</td>\n",
" <td>3124.08076212353</td>\n",
" <td>3095.3596925636</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>Bosnia and Herzegovina</td>\n",
" <td>BA</td>\n",
" <td>BAM</td>\n",
" <td>1746.48638346723</td>\n",
" <td>2192.64707824367</td>\n",
" <td>2619.75325753727</td>\n",
" <td>2928.26359035282</td>\n",
" <td>3351.96339986152</td>\n",
" <td>4107.99623197216</td>\n",
" <td>4974.66226666137</td>\n",
" <td>4586.20631315947</td>\n",
" <td>4475.08813004565</td>\n",
" <td>4860.78181134244</td>\n",
" <td>4494.64064038047</td>\n",
" <td>4748.04069226421</td>\n",
" <td>4851.66052786926</td>\n",
" <td>4197.80730449044</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>Botswana</td>\n",
" <td>BW</td>\n",
" <td>BWP</td>\n",
" <td>3044.12735338963</td>\n",
" <td>4149.04137748834</td>\n",
" <td>4879.45946154727</td>\n",
" <td>5327.8535176786</td>\n",
" <td>5342.1403362253</td>\n",
" <td>5666.63784692568</td>\n",
" <td>5561.89823998598</td>\n",
" <td>5115.11924667202</td>\n",
" <td>6244.00257387272</td>\n",
" <td>7504.85090744898</td>\n",
" <td>6885.82968106945</td>\n",
" <td>6806.67746673071</td>\n",
" <td>7153.44432535212</td>\n",
" <td>6360.64477568565</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>Brazil</td>\n",
" <td>BR</td>\n",
" <td>BRL</td>\n",
" <td>2805.71725723054</td>\n",
" <td>3040.50649558819</td>\n",
" <td>3596.22457976056</td>\n",
" <td>4730.65346838158</td>\n",
" <td>5808.34054715979</td>\n",
" <td>7246.87010479067</td>\n",
" <td>8706.81914190374</td>\n",
" <td>8474.88106576607</td>\n",
" <td>11121.4209541496</td>\n",
" <td>13039.1216499582</td>\n",
" <td>12157.3082176473</td>\n",
" <td>12071.7779871352</td>\n",
" <td>11728.7993875108</td>\n",
" <td>8538.5899749574</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>British Virgin Islands</td>\n",
" <td>VG</td>\n",
" <td>USD</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>Brunei Darussalam</td>\n",
" <td>BN</td>\n",
" <td>BND</td>\n",
" <td>17016.9434933055</td>\n",
" <td>18758.9808946915</td>\n",
" <td>22131.9460641106</td>\n",
" <td>26337.9181126619</td>\n",
" <td>31157.6884478525</td>\n",
" <td>32707.7043073602</td>\n",
" <td>37798.3935034007</td>\n",
" <td>27726.481053695</td>\n",
" <td>31453.2243965354</td>\n",
" <td>41787.0214028978</td>\n",
" <td>41807.6533410575</td>\n",
" <td>39151.2342290391</td>\n",
" <td>40979.6419433378</td>\n",
" <td>36607.9278817468</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>Bulgaria</td>\n",
" <td>BG</td>\n",
" <td>BGN</td>\n",
" <td>2079.2289749196</td>\n",
" <td>2693.75876041107</td>\n",
" <td>3353.56414854374</td>\n",
" <td>3852.97775647268</td>\n",
" <td>4455.69022418578</td>\n",
" <td>5932.89967659315</td>\n",
" <td>7296.12247858585</td>\n",
" <td>6955.98773253421</td>\n",
" <td>6752.55217774882</td>\n",
" <td>7750.03988003072</td>\n",
" <td>7333.35507303945</td>\n",
" <td>7656.63850554922</td>\n",
" <td>7851.26542804234</td>\n",
" <td>6819.86910816324</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>Sweden</td>\n",
" <td>SE</td>\n",
" <td>SEK</td>\n",
" <td>29571.7044643283</td>\n",
" <td>36961.4253671424</td>\n",
" <td>42442.2204473133</td>\n",
" <td>43085.353145957</td>\n",
" <td>46256.4716010495</td>\n",
" <td>53324.3793724756</td>\n",
" <td>55746.8423811175</td>\n",
" <td>46207.0592032962</td>\n",
" <td>52076.4305245885</td>\n",
" <td>59593.6847982389</td>\n",
" <td>57134.0770682404</td>\n",
" <td>60283.24522267</td>\n",
" <td>58899.9797944845</td>\n",
" <td>50272.9415019928</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>Switzerland</td>\n",
" <td>CH</td>\n",
" <td>CHF</td>\n",
" <td>41336.7219170303</td>\n",
" <td>47960.5649721577</td>\n",
" <td>53255.9763084633</td>\n",
" <td>54797.5466345741</td>\n",
" <td>57348.9278823975</td>\n",
" <td>63223.467775151</td>\n",
" <td>72119.5608730311</td>\n",
" <td>69672.0047147337</td>\n",
" <td>74277.1205125567</td>\n",
" <td>88002.6095703805</td>\n",
" <td>83208.68654235</td>\n",
" <td>84669.2929367996</td>\n",
" <td>85610.8420285261</td>\n",
" <td>80214.7301520483</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>Syrian Arab Republic</td>\n",
" <td>SY</td>\n",
" <td>SYP</td>\n",
" <td>1269.72920825685</td>\n",
" <td>1261.42609007136</td>\n",
" <td>1419.59337922665</td>\n",
" <td>1591.53019241227</td>\n",
" <td>1779.82104926154</td>\n",
" <td>2079.98786380715</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>Tajikistan</td>\n",
" <td>TJ</td>\n",
" <td>TJS</td>\n",
" <td>190.604911236529</td>\n",
" <td>237.89319314008</td>\n",
" <td>311.424112807574</td>\n",
" <td>339.768076770367</td>\n",
" <td>407.252611650134</td>\n",
" <td>523.947651220881</td>\n",
" <td>711.503629870563</td>\n",
" <td>671.544008840534</td>\n",
" <td>744.189892165383</td>\n",
" <td>841.219870374428</td>\n",
" <td>962.439124853526</td>\n",
" <td>1048.66690599689</td>\n",
" <td>1113.36635446715</td>\n",
" <td>925.91188767081</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>Tanzania</td>\n",
" <td>TZ</td>\n",
" <td>TZS</td>\n",
" <td>310.207276508511</td>\n",
" <td>325.550773719717</td>\n",
" <td>348.052371292798</td>\n",
" <td>446.157893998536</td>\n",
" <td>475.908765113372</td>\n",
" <td>533.172396689392</td>\n",
" <td>657.728743357642</td>\n",
" <td>665.344002868127</td>\n",
" <td>708.521932325363</td>\n",
" <td>740.383900829825</td>\n",
" <td>827.52888076909</td>\n",
" <td>909.330141239446</td>\n",
" <td>954.618987954616</td>\n",
" <td>864.857502346707</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>Thailand</td>\n",
" <td>TH</td>\n",
" <td>THB</td>\n",
" <td>2093.97920641937</td>\n",
" <td>2349.38452566541</td>\n",
" <td>2643.47893487535</td>\n",
" <td>2874.38627417759</td>\n",
" <td>3351.11763286401</td>\n",
" <td>3962.7504988544</td>\n",
" <td>4384.78267515745</td>\n",
" <td>4231.14036778126</td>\n",
" <td>5111.90920222917</td>\n",
" <td>5539.49436810396</td>\n",
" <td>5915.22114668686</td>\n",
" <td>6225.05228315387</td>\n",
" <td>5969.94011583791</td>\n",
" <td>5816.44068998475</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>Timor-Leste</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>496.17975117256</td>\n",
" <td>487.394976066002</td>\n",
" <td>484.088448984765</td>\n",
" <td>501.429226481591</td>\n",
" <td>464.835169248192</td>\n",
" <td>551.720598424389</td>\n",
" <td>673.374537904</td>\n",
" <td>780.261110851448</td>\n",
" <td>875.836569271265</td>\n",
" <td>1015.71592799663</td>\n",
" <td>1127.10821457355</td>\n",
" <td>1117.73125130819</td>\n",
" <td>1131.23085071824</td>\n",
" <td>1134.42642789183</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>Togo</td>\n",
" <td>TG</td>\n",
" <td>XOF</td>\n",
" <td>286.758081572586</td>\n",
" <td>316.792068666893</td>\n",
" <td>356.830803515721</td>\n",
" <td>379.18092890047</td>\n",
" <td>384.288555620343</td>\n",
" <td>428.401561823965</td>\n",
" <td>522.625007010443</td>\n",
" <td>508.54052572385</td>\n",
" <td>496.482494202806</td>\n",
" <td>572.025703222528</td>\n",
" <td>573.207476512184</td>\n",
" <td>589.014053731293</td>\n",
" <td>629.9976439467</td>\n",
" <td>547.974683363941</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>Tonga</td>\n",
" <td>TO</td>\n",
" <td>TOP</td>\n",
" <td>1836.29040439251</td>\n",
" <td>2089.21704269256</td>\n",
" <td>2357.14647444959</td>\n",
" <td>2565.38579890357</td>\n",
" <td>2837.07547156741</td>\n",
" <td>2932.96275815712</td>\n",
" <td>3307.28239321081</td>\n",
" <td>3106.90237557772</td>\n",
" <td>3557.73718366504</td>\n",
" <td>4226.69274653294</td>\n",
" <td>4364.30924422214</td>\n",
" <td>4117.31098292096</td>\n",
" <td>4114.05211511279</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>Trinidad and Tobago</td>\n",
" <td>TT</td>\n",
" <td>TTD</td>\n",
" <td>7049.61006145836</td>\n",
" <td>8804.5186659639</td>\n",
" <td>10290.5191436384</td>\n",
" <td>12323.1365595732</td>\n",
" <td>14095.9958152811</td>\n",
" <td>16530.1804420146</td>\n",
" <td>21188.118565877</td>\n",
" <td>14508.8137365799</td>\n",
" <td>15840.4426914159</td>\n",
" <td>18287.3907851354</td>\n",
" <td>18322.323800986</td>\n",
" <td>20217.0322820943</td>\n",
" <td>21317.449265568</td>\n",
" <td>20444.0785895112</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>Tunisia</td>\n",
" <td>TN</td>\n",
" <td>TND</td>\n",
" <td>2373.83647757576</td>\n",
" <td>2790.00436823287</td>\n",
" <td>3139.53720163156</td>\n",
" <td>3217.96864628265</td>\n",
" <td>3394.42897986889</td>\n",
" <td>3805.15293730174</td>\n",
" <td>4342.82317730308</td>\n",
" <td>4162.5096689683</td>\n",
" <td>4176.59159013024</td>\n",
" <td>4291.87604315683</td>\n",
" <td>4179.46434367471</td>\n",
" <td>4248.89127558615</td>\n",
" <td>4328.90419734881</td>\n",
" <td>3872.51208364171</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>Turkey</td>\n",
" <td>TR</td>\n",
" <td>TRY</td>\n",
" <td>3570.54626341295</td>\n",
" <td>4586.81120315865</td>\n",
" <td>5855.53865983905</td>\n",
" <td>7117.23324132191</td>\n",
" <td>7727.27240453727</td>\n",
" <td>9309.50947782175</td>\n",
" <td>10382.3181608988</td>\n",
" <td>8623.94962718666</td>\n",
" <td>10111.5177049589</td>\n",
" <td>10538.4351203671</td>\n",
" <td>10539.3703371146</td>\n",
" <td>10800.3579763053</td>\n",
" <td>10303.8988002501</td>\n",
" <td>9130.02606479616</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>Turkmenistan</td>\n",
" <td>TM</td>\n",
" <td>TMT</td>\n",
" <td>969.970033452985</td>\n",
" <td>1286.01426124964</td>\n",
" <td>1455.93604950756</td>\n",
" <td>1706.95672639245</td>\n",
" <td>2140.45547216715</td>\n",
" <td>2606.74197588003</td>\n",
" <td>3918.93492678718</td>\n",
" <td>4059.96151102083</td>\n",
" <td>4479.01235418457</td>\n",
" <td>5724.53710231112</td>\n",
" <td>6797.72116602834</td>\n",
" <td>7480.32167773692</td>\n",
" <td>8193.72029690445</td>\n",
" <td>6947.84002260404</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>200</th>\n",
" <td>Turks and Caicos Islands</td>\n",
" <td>TC</td>\n",
" <td>USD</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>201</th>\n",
" <td>Tuvalu</td>\n",
" <td>TV</td>\n",
" <td>AUD</td>\n",
" <td>1621.33358266022</td>\n",
" <td>1901.03347628001</td>\n",
" <td>2232.60251748372</td>\n",
" <td>2252.89288563217</td>\n",
" <td>2353.35608772946</td>\n",
" <td>2768.37095732057</td>\n",
" <td>3094.62809172302</td>\n",
" <td>2763.16030537848</td>\n",
" <td>3238.37576273905</td>\n",
" <td>3993.50025430234</td>\n",
" <td>4044.19378022487</td>\n",
" <td>3880.19087861123</td>\n",
" <td>3826.90331140252</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>202</th>\n",
" <td>Uganda</td>\n",
" <td>UG</td>\n",
" <td>UGX</td>\n",
" <td>243.674624856652</td>\n",
" <td>241.694801118865</td>\n",
" <td>292.843015035141</td>\n",
" <td>321.435761373761</td>\n",
" <td>342.837263983568</td>\n",
" <td>409.87032601315</td>\n",
" <td>459.109775900068</td>\n",
" <td>557.523595605241</td>\n",
" <td>608.813023856722</td>\n",
" <td>591.438623816353</td>\n",
" <td>656.398072749334</td>\n",
" <td>674.341641819883</td>\n",
" <td>714.567356471156</td>\n",
" <td>675.573466220693</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>203</th>\n",
" <td>Ukraine</td>\n",
" <td>UA</td>\n",
" <td>UAH</td>\n",
" <td>879.475048622777</td>\n",
" <td>1048.52248790763</td>\n",
" <td>1367.35243333629</td>\n",
" <td>1828.71762576598</td>\n",
" <td>2303.01883093184</td>\n",
" <td>3068.60899799696</td>\n",
" <td>3891.03782318207</td>\n",
" <td>2545.4803410735</td>\n",
" <td>2973.99648071562</td>\n",
" <td>3569.75702740477</td>\n",
" <td>3855.4212801318</td>\n",
" <td>3986.28296611562</td>\n",
" <td>3065.16422265266</td>\n",
" <td>2114.95471628444</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>United Arab Emirates</td>\n",
" <td>AE</td>\n",
" <td>AED</td>\n",
" <td>32355.4095972427</td>\n",
" <td>34294.8939976005</td>\n",
" <td>37179.6818919642</td>\n",
" <td>40298.5242178562</td>\n",
" <td>42950.1005841305</td>\n",
" <td>42913.7840342254</td>\n",
" <td>45720.0178979792</td>\n",
" <td>32905.0538494054</td>\n",
" <td>34341.9112921486</td>\n",
" <td>39901.2209155518</td>\n",
" <td>41712.1242109135</td>\n",
" <td>42831.0891322689</td>\n",
" <td>43962.7136932011</td>\n",
" <td>40438.3763627115</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>205</th>\n",
" <td>United Kingdom</td>\n",
" <td>GB</td>\n",
" <td>GBP</td>\n",
" <td>28301.2083322425</td>\n",
" <td>32575.0919626199</td>\n",
" <td>38305.8726859929</td>\n",
" <td>40047.905967007</td>\n",
" <td>42534.3062613449</td>\n",
" <td>48428.1574527987</td>\n",
" <td>45195.1569273881</td>\n",
" <td>37166.2759654944</td>\n",
" <td>38292.8711313583</td>\n",
" <td>41020.3769643089</td>\n",
" <td>41294.5148008666</td>\n",
" <td>42294.8901157814</td>\n",
" <td>46278.5202128829</td>\n",
" <td>43734.0001709187</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>206</th>\n",
" <td>United States</td>\n",
" <td>US</td>\n",
" <td>USD</td>\n",
" <td>38166.0378407812</td>\n",
" <td>39677.1983481058</td>\n",
" <td>41921.8097617892</td>\n",
" <td>44307.9205848603</td>\n",
" <td>46437.0671173065</td>\n",
" <td>48061.5376613353</td>\n",
" <td>48401.4273403899</td>\n",
" <td>47001.5553496818</td>\n",
" <td>48374.0867933094</td>\n",
" <td>49781.8006563523</td>\n",
" <td>51433.0470904727</td>\n",
" <td>52660.2951049798</td>\n",
" <td>54398.4600093994</td>\n",
" <td>55836.7926308733</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>207</th>\n",
" <td>Uruguay</td>\n",
" <td>UY</td>\n",
" <td>UYU</td>\n",
" <td>4088.77254119908</td>\n",
" <td>3622.05228427976</td>\n",
" <td>4117.30885333007</td>\n",
" <td>5220.95739601735</td>\n",
" <td>5877.87960762231</td>\n",
" <td>7009.67815952936</td>\n",
" <td>9062.29053512906</td>\n",
" <td>9415.15358319032</td>\n",
" <td>11938.2750549849</td>\n",
" <td>14166.5576669096</td>\n",
" <td>15092.4720586676</td>\n",
" <td>16881.38400062</td>\n",
" <td>16737.973101175</td>\n",
" <td>15573.9009189374</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>208</th>\n",
" <td>Uzbekistan</td>\n",
" <td>UZ</td>\n",
" <td>UZS</td>\n",
" <td>383.349499748749</td>\n",
" <td>396.129968981304</td>\n",
" <td>465.119886944025</td>\n",
" <td>546.776850185552</td>\n",
" <td>642.960414644088</td>\n",
" <td>830.407694204322</td>\n",
" <td>1023.11964110698</td>\n",
" <td>1181.84735960066</td>\n",
" <td>1377.08214046938</td>\n",
" <td>1544.82777273524</td>\n",
" <td>1719.03619624155</td>\n",
" <td>1877.9645118434</td>\n",
" <td>2052.58678135925</td>\n",
" <td>2132.07244181734</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>209</th>\n",
" <td>Vanuatu</td>\n",
" <td>VU</td>\n",
" <td>VUV</td>\n",
" <td>1353.9278386398</td>\n",
" <td>1580.51066802466</td>\n",
" <td>1787.9382648014</td>\n",
" <td>1886.38830966499</td>\n",
" <td>2047.08828520065</td>\n",
" <td>2393.3346212201</td>\n",
" <td>2698.02124012432</td>\n",
" <td>2643.47578534313</td>\n",
" <td>2965.75223011673</td>\n",
" <td>3275.02398203673</td>\n",
" <td>3158.4209735273</td>\n",
" <td>3167.05530330465</td>\n",
" <td>3147.96485986836</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>210</th>\n",
" <td>Venezuela, RB</td>\n",
" <td>VE</td>\n",
" <td>VEF</td>\n",
" <td>3657.19374768603</td>\n",
" <td>3233.9561063252</td>\n",
" <td>4273.36537157056</td>\n",
" <td>5435.87225994853</td>\n",
" <td>6740.23677858669</td>\n",
" <td>8325.21658255278</td>\n",
" <td>11224.6467026883</td>\n",
" <td>11534.8406001136</td>\n",
" <td>13581.3533771018</td>\n",
" <td>10754.5928790654</td>\n",
" <td>12771.5950361107</td>\n",
" <td>12265.03113567</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>211</th>\n",
" <td>Vietnam</td>\n",
" <td>VN</td>\n",
" <td>VND</td>\n",
" <td>477.105876263106</td>\n",
" <td>530.861849364997</td>\n",
" <td>606.904378261988</td>\n",
" <td>699.499778976363</td>\n",
" <td>796.671573774518</td>\n",
" <td>919.209265568078</td>\n",
" <td>1164.61252461712</td>\n",
" <td>1232.36967118834</td>\n",
" <td>1333.58352635481</td>\n",
" <td>1542.67043610149</td>\n",
" <td>1754.5479738641</td>\n",
" <td>1907.56438167972</td>\n",
" <td>2052.31908380089</td>\n",
" <td>2111.13802366815</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>212</th>\n",
" <td>Virgin Islands (U.S.)</td>\n",
" <td>VI</td>\n",
" <td>USD</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>213</th>\n",
" <td>West Bank and Gaza</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1156.21747345769</td>\n",
" <td>1257.69857009689</td>\n",
" <td>1337.56572430673</td>\n",
" <td>1455.18787518115</td>\n",
" <td>1441.46170046742</td>\n",
" <td>1575.56340027289</td>\n",
" <td>1855.45702045882</td>\n",
" <td>1963.20151865719</td>\n",
" <td>2338.71987682303</td>\n",
" <td>2663.53702496611</td>\n",
" <td>2787.16973802917</td>\n",
" <td>2992.20099455427</td>\n",
" <td>2960.77800405245</td>\n",
" <td>2866.80010121789</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>214</th>\n",
" <td>Yemen, Rep.</td>\n",
" <td>YE</td>\n",
" <td>YER</td>\n",
" <td>567.821963311624</td>\n",
" <td>607.915804267557</td>\n",
" <td>696.054960696925</td>\n",
" <td>817.082416653512</td>\n",
" <td>904.605600055261</td>\n",
" <td>1181.2151760728</td>\n",
" <td>1361.7172085227</td>\n",
" <td>1239.83711886653</td>\n",
" <td>1310.05383929542</td>\n",
" <td>1282.39883187217</td>\n",
" <td>1289.03407763668</td>\n",
" <td>1408.14619260488</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>215</th>\n",
" <td>Zambia</td>\n",
" <td>ZM</td>\n",
" <td>ZMW</td>\n",
" <td>376.468039539246</td>\n",
" <td>429.007277894455</td>\n",
" <td>530.553584072736</td>\n",
" <td>691.80945858671</td>\n",
" <td>1030.31535972563</td>\n",
" <td>1103.48657711875</td>\n",
" <td>1365.72120522548</td>\n",
" <td>1134.77299782945</td>\n",
" <td>1456.12652618031</td>\n",
" <td>1635.54730435222</td>\n",
" <td>1724.74356387435</td>\n",
" <td>1839.52248112115</td>\n",
" <td>1725.97454864009</td>\n",
" <td>1307.78861109883</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>216</th>\n",
" <td>Zimbabwe</td>\n",
" <td>ZW</td>\n",
" <td>ZWL</td>\n",
" <td>499.716414957462</td>\n",
" <td>448.373192699451</td>\n",
" <td>451.171588554028</td>\n",
" <td>443.240135984532</td>\n",
" <td>414.680115131526</td>\n",
" <td>397.956872258099</td>\n",
" <td>327.199083662345</td>\n",
" <td>594.495968478092</td>\n",
" <td>674.268695411166</td>\n",
" <td>768.556409302399</td>\n",
" <td>850.827696604891</td>\n",
" <td>905.500321786172</td>\n",
" <td>931.19818468692</td>\n",
" <td>890.416087751634</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>217 rows × 18 columns</p>\n",
"</div>"
],
"text/plain": [
" name country_code currency_code 2002 \\\n",
"0 Afghanistan AF AFN 192.153528278789 \n",
"1 Albania AL ALL 1453.64277660853 \n",
"2 Algeria DZ DZD 1774.29202079911 \n",
"3 American Samoa AS USD NaN \n",
"4 Andorra NaN NaN 24175.3727542522 \n",
"5 Angola AO AOA 775.765518459716 \n",
"6 Antigua and Barbuda AG XCD 10027.8562205839 \n",
"7 Argentina AR ARS 2579.18819898884 \n",
"8 Armenia AM AMD 779.829626131555 \n",
"9 Aruba AW AWG 20433.6541088167 \n",
"10 Australia AU AUD 20059.4520721372 \n",
"11 Austria AT EUR 26351.3756769542 \n",
"12 Azerbaijan AZ AZN 763.101212220367 \n",
"13 Bahamas, The BS BSD 22505.4047934793 \n",
"14 Bahrain BH BHD 13279.0457951397 \n",
"15 Bangladesh BD BDT 401.708153328187 \n",
"16 Barbados BB BBD 11674.9361829092 \n",
"17 Belarus BY BYR 1479.46532113219 \n",
"18 Belgium BE EUR 25052.3302823 \n",
"19 Belize BZ BZD 3556.61608225719 \n",
"20 Benin BJ XOF 411.959075281789 \n",
"21 Bermuda BM BMD 62583.1002034588 \n",
"22 Bhutan BT INR 897.445333164014 \n",
"23 Bolivia BO BOB 913.575853422027 \n",
"24 Bosnia and Herzegovina BA BAM 1746.48638346723 \n",
"25 Botswana BW BWP 3044.12735338963 \n",
"26 Brazil BR BRL 2805.71725723054 \n",
"27 British Virgin Islands VG USD NaN \n",
"28 Brunei Darussalam BN BND 17016.9434933055 \n",
"29 Bulgaria BG BGN 2079.2289749196 \n",
".. ... ... ... ... \n",
"187 Sweden SE SEK 29571.7044643283 \n",
"188 Switzerland CH CHF 41336.7219170303 \n",
"189 Syrian Arab Republic SY SYP 1269.72920825685 \n",
"190 Tajikistan TJ TJS 190.604911236529 \n",
"191 Tanzania TZ TZS 310.207276508511 \n",
"192 Thailand TH THB 2093.97920641937 \n",
"193 Timor-Leste NaN NaN 496.17975117256 \n",
"194 Togo TG XOF 286.758081572586 \n",
"195 Tonga TO TOP 1836.29040439251 \n",
"196 Trinidad and Tobago TT TTD 7049.61006145836 \n",
"197 Tunisia TN TND 2373.83647757576 \n",
"198 Turkey TR TRY 3570.54626341295 \n",
"199 Turkmenistan TM TMT 969.970033452985 \n",
"200 Turks and Caicos Islands TC USD NaN \n",
"201 Tuvalu TV AUD 1621.33358266022 \n",
"202 Uganda UG UGX 243.674624856652 \n",
"203 Ukraine UA UAH 879.475048622777 \n",
"204 United Arab Emirates AE AED 32355.4095972427 \n",
"205 United Kingdom GB GBP 28301.2083322425 \n",
"206 United States US USD 38166.0378407812 \n",
"207 Uruguay UY UYU 4088.77254119908 \n",
"208 Uzbekistan UZ UZS 383.349499748749 \n",
"209 Vanuatu VU VUV 1353.9278386398 \n",
"210 Venezuela, RB VE VEF 3657.19374768603 \n",
"211 Vietnam VN VND 477.105876263106 \n",
"212 Virgin Islands (U.S.) VI USD NaN \n",
"213 West Bank and Gaza NaN NaN 1156.21747345769 \n",
"214 Yemen, Rep. YE YER 567.821963311624 \n",
"215 Zambia ZM ZMW 376.468039539246 \n",
"216 Zimbabwe ZW ZWL 499.716414957462 \n",
"\n",
" 2003 2004 2005 2006 \\\n",
"0 203.651040923182 224.914712193371 257.175794656273 280.245644106914 \n",
"1 1890.68155743544 2416.5882350701 2709.14293056201 3005.0129033756 \n",
"2 2094.89330213298 2600.00651972559 3102.03738422673 3467.54474008596 \n",
"3 NaN NaN NaN NaN \n",
"4 31742.9925847537 37235.4500323146 39990.3304085679 42417.2291456984 \n",
"5 850.075694129697 1135.60456355085 1576.16280066689 2253.83885003865 \n",
"6 10382.6309004545 10993.3692472668 12079.8656950416 13599.908857304 \n",
"7 3330.42866006847 4251.5653466058 5096.25833247505 5904.67813228342 \n",
"8 924.464009817761 1181.9684454224 1625.40776912682 2126.61866107184 \n",
"9 20834.9397101237 22566.6821576324 23302.8319880055 24015.4206122701 \n",
"10 23440.0053221856 30440.8548786229 33982.9504271591 36084.8589777475 \n",
"11 32102.9305523558 36693.4026205182 38242.0425174699 40430.993614499 \n",
"12 883.614008967961 1045.02641527642 1578.36733030667 2473.08577636837 \n",
"13 22008.4337005989 21995.5199216219 23405.8795479327 23721.1562800587 \n",
"14 14541.6160485141 16275.1804236433 18418.0726743768 19669.3195545631 \n",
"15 434.046563233432 462.274879844841 485.852888073473 495.853780201055 \n",
"16 12028.8987405468 12869.3365947615 14223.7777039775 15646.815008726 \n",
"17 1819.4790277163 2378.37489391196 3126.36777779462 3848.58620300891 \n",
"18 30743.9569254283 35589.7129457001 36967.2829204297 38852.3610339939 \n",
"19 3679.79281542143 3831.60983030588 3933.2343731798 4187.23288999866 \n",
"20 509.461088697817 570.685501333771 587.080212422838 609.018608681583 \n",
"21 66111.7252270036 70359.3191088798 75882.0338560339 83912.6977976846 \n",
"22 1009.00623184688 1107.92059564068 1257.54864008661 1346.08577480046 \n",
"23 917.36431048617 978.334757576746 1046.4278428307 1233.59297372996 \n",
"24 2192.64707824367 2619.75325753727 2928.26359035282 3351.96339986152 \n",
"25 4149.04137748834 4879.45946154727 5327.8535176786 5342.1403362253 \n",
"26 3040.50649558819 3596.22457976056 4730.65346838158 5808.34054715979 \n",
"27 NaN NaN NaN NaN \n",
"28 18758.9808946915 22131.9460641106 26337.9181126619 31157.6884478525 \n",
"29 2693.75876041107 3353.56414854374 3852.97775647268 4455.69022418578 \n",
".. ... ... ... ... \n",
"187 36961.4253671424 42442.2204473133 43085.353145957 46256.4716010495 \n",
"188 47960.5649721577 53255.9763084633 54797.5466345741 57348.9278823975 \n",
"189 1261.42609007136 1419.59337922665 1591.53019241227 1779.82104926154 \n",
"190 237.89319314008 311.424112807574 339.768076770367 407.252611650134 \n",
"191 325.550773719717 348.052371292798 446.157893998536 475.908765113372 \n",
"192 2349.38452566541 2643.47893487535 2874.38627417759 3351.11763286401 \n",
"193 487.394976066002 484.088448984765 501.429226481591 464.835169248192 \n",
"194 316.792068666893 356.830803515721 379.18092890047 384.288555620343 \n",
"195 2089.21704269256 2357.14647444959 2565.38579890357 2837.07547156741 \n",
"196 8804.5186659639 10290.5191436384 12323.1365595732 14095.9958152811 \n",
"197 2790.00436823287 3139.53720163156 3217.96864628265 3394.42897986889 \n",
"198 4586.81120315865 5855.53865983905 7117.23324132191 7727.27240453727 \n",
"199 1286.01426124964 1455.93604950756 1706.95672639245 2140.45547216715 \n",
"200 NaN NaN NaN NaN \n",
"201 1901.03347628001 2232.60251748372 2252.89288563217 2353.35608772946 \n",
"202 241.694801118865 292.843015035141 321.435761373761 342.837263983568 \n",
"203 1048.52248790763 1367.35243333629 1828.71762576598 2303.01883093184 \n",
"204 34294.8939976005 37179.6818919642 40298.5242178562 42950.1005841305 \n",
"205 32575.0919626199 38305.8726859929 40047.905967007 42534.3062613449 \n",
"206 39677.1983481058 41921.8097617892 44307.9205848603 46437.0671173065 \n",
"207 3622.05228427976 4117.30885333007 5220.95739601735 5877.87960762231 \n",
"208 396.129968981304 465.119886944025 546.776850185552 642.960414644088 \n",
"209 1580.51066802466 1787.9382648014 1886.38830966499 2047.08828520065 \n",
"210 3233.9561063252 4273.36537157056 5435.87225994853 6740.23677858669 \n",
"211 530.861849364997 606.904378261988 699.499778976363 796.671573774518 \n",
"212 NaN NaN NaN NaN \n",
"213 1257.69857009689 1337.56572430673 1455.18787518115 1441.46170046742 \n",
"214 607.915804267557 696.054960696925 817.082416653512 904.605600055261 \n",
"215 429.007277894455 530.553584072736 691.80945858671 1030.31535972563 \n",
"216 448.373192699451 451.171588554028 443.240135984532 414.680115131526 \n",
"\n",
" 2007 2008 2009 2010 \\\n",
"0 380.400955186598 384.131681276838 458.955781585831 569.940728793286 \n",
"1 3603.01368536638 4370.53964653148 4114.13654490945 4094.35883191918 \n",
"2 3939.55993939808 4912.25194081995 3875.82209542426 4473.48644568115 \n",
"3 NaN NaN NaN NaN \n",
"4 47253.5297963111 46735.9995745016 42701.447136255 39639.386021211 \n",
"5 3151.02243105289 4242.36306234092 3678.94765447179 3886.47935432524 \n",
"6 15276.0682646698 15786.1728395062 13979.2626925883 13017.3103875487 \n",
"7 7226.27029452745 8992.58961919674 8198.56611136286 10332.0323662966 \n",
"8 3080.97095943572 3919.97547381061 2915.5839059087 3124.78401786195 \n",
"9 25921.5382341406 27549.8894224976 24640.4212441218 24289.1415161326 \n",
"10 40957.8304392487 49628.1151270179 42715.1322619629 51845.6548605562 \n",
"11 46586.6502529235 51386.3766511975 47654.1872090808 46659.8408181344 \n",
"12 3851.43786871172 5574.60380218613 4950.29479142375 5842.80578358576 \n",
"13 24306.1424243044 23657.365306222 22043.0125711709 21920.5165867583 \n",
"14 21167.6187062133 23043.0253174017 19166.7082382358 20386.0175551116 \n",
"15 543.082263122362 618.075883559283 683.614422272329 760.331935200195 \n",
"16 16461.8292691759 16569.6049618665 16526.2545517227 15901.4329353355 \n",
"17 4735.95688918873 6376.17311491284 5176.04470138203 5818.8548592158 \n",
"18 44403.8313061102 48424.5892730273 44880.5601517887 44382.8797683492 \n",
"19 4324.83101711444 4470.22079597603 4258.84287648324 4344.13666906088 \n",
"20 685.551675107742 794.870176064085 768.013476447657 732.953622726674 \n",
"21 90849.5869806436 93605.7481653976 88463.3128161375 88207.3275597322 \n",
"22 1755.16170904287 1810.57617704401 1786.81067200588 2201.29307778936 \n",
"23 1389.6317502607 1736.92401415151 1776.85718962366 1981.16010525701 \n",
"24 4107.99623197216 4974.66226666137 4586.20631315947 4475.08813004565 \n",
"25 5666.63784692568 5561.89823998598 5115.11924667202 6244.00257387272 \n",
"26 7246.87010479067 8706.81914190374 8474.88106576607 11121.4209541496 \n",
"27 NaN NaN NaN NaN \n",
"28 32707.7043073602 37798.3935034007 27726.481053695 31453.2243965354 \n",
"29 5932.89967659315 7296.12247858585 6955.98773253421 6752.55217774882 \n",
".. ... ... ... ... \n",
"187 53324.3793724756 55746.8423811175 46207.0592032962 52076.4305245885 \n",
"188 63223.467775151 72119.5608730311 69672.0047147337 74277.1205125567 \n",
"189 2079.98786380715 NaN NaN NaN \n",
"190 523.947651220881 711.503629870563 671.544008840534 744.189892165383 \n",
"191 533.172396689392 657.728743357642 665.344002868127 708.521932325363 \n",
"192 3962.7504988544 4384.78267515745 4231.14036778126 5111.90920222917 \n",
"193 551.720598424389 673.374537904 780.261110851448 875.836569271265 \n",
"194 428.401561823965 522.625007010443 508.54052572385 496.482494202806 \n",
"195 2932.96275815712 3307.28239321081 3106.90237557772 3557.73718366504 \n",
"196 16530.1804420146 21188.118565877 14508.8137365799 15840.4426914159 \n",
"197 3805.15293730174 4342.82317730308 4162.5096689683 4176.59159013024 \n",
"198 9309.50947782175 10382.3181608988 8623.94962718666 10111.5177049589 \n",
"199 2606.74197588003 3918.93492678718 4059.96151102083 4479.01235418457 \n",
"200 NaN NaN NaN NaN \n",
"201 2768.37095732057 3094.62809172302 2763.16030537848 3238.37576273905 \n",
"202 409.87032601315 459.109775900068 557.523595605241 608.813023856722 \n",
"203 3068.60899799696 3891.03782318207 2545.4803410735 2973.99648071562 \n",
"204 42913.7840342254 45720.0178979792 32905.0538494054 34341.9112921486 \n",
"205 48428.1574527987 45195.1569273881 37166.2759654944 38292.8711313583 \n",
"206 48061.5376613353 48401.4273403899 47001.5553496818 48374.0867933094 \n",
"207 7009.67815952936 9062.29053512906 9415.15358319032 11938.2750549849 \n",
"208 830.407694204322 1023.11964110698 1181.84735960066 1377.08214046938 \n",
"209 2393.3346212201 2698.02124012432 2643.47578534313 2965.75223011673 \n",
"210 8325.21658255278 11224.6467026883 11534.8406001136 13581.3533771018 \n",
"211 919.209265568078 1164.61252461712 1232.36967118834 1333.58352635481 \n",
"212 NaN NaN NaN NaN \n",
"213 1575.56340027289 1855.45702045882 1963.20151865719 2338.71987682303 \n",
"214 1181.2151760728 1361.7172085227 1239.83711886653 1310.05383929542 \n",
"215 1103.48657711875 1365.72120522548 1134.77299782945 1456.12652618031 \n",
"216 397.956872258099 327.199083662345 594.495968478092 674.268695411166 \n",
"\n",
" 2011 2012 2013 2014 \\\n",
"0 622.379654358451 690.842629014956 653.347488111011 633.947864294639 \n",
"1 4437.8119990258 4247.83985201907 4412.34557813421 4588.64944014811 \n",
"2 5447.40397556569 5583.61615950131 5491.6144135648 5484.0668056148 \n",
"3 NaN NaN NaN NaN \n",
"4 41630.0525792977 39666.3692147448 42806.5224483021 NaN \n",
"5 4744.98762949589 5086.8484258086 5327.14889219232 5232.69050054132 \n",
"6 12817.8415733094 13525.616220134 13342.0849977054 13432.0792079208 \n",
"7 12800.2018563295 13040.306395228 13027.2048221392 12324.9387857728 \n",
"8 3417.17183599915 3565.5175749254 3716.82892254464 3873.53356580682 \n",
"9 25353.7875446441 NaN NaN NaN \n",
"10 62216.5471294133 67646.1038529626 67652.6832146189 61995.8296976 \n",
"11 51123.5613291663 48324.2540367606 50557.8038059874 51148.3588760796 \n",
"12 7189.69122920765 7393.77187697623 7811.6214184582 7886.45914367274 \n",
"13 21514.8986531628 22112.6083547268 22315.6036533886 22217.4941392075 \n",
"14 22238.7119502059 23063.1322870426 24378.9448284188 24855.2156350086 \n",
"15 838.547801702232 858.933362587621 954.396399715624 1086.80008676935 \n",
"16 15530.8942915589 15317.1390013495 15153.8213753482 15366.2926106288 \n",
"17 6305.77366247653 6721.83490773968 7722.12335060436 8025.30435552468 \n",
"18 47699.8070518961 44734.4523465803 46622.4679873931 47299.8601085612 \n",
"19 4516.23303047149 4673.55519784264 4723.59432062825 4884.3686203818 \n",
"20 799.03555913143 807.688451017232 882.638633279988 903.464924007693 \n",
"21 85973.158416455 85458.455507886 85748.0654143782 NaN \n",
"22 2485.78705216849 2452.15158793741 2383.04472990264 2560.52213174131 \n",
"23 2377.70068972888 2645.29027433174 2948.03291763073 3124.08076212353 \n",
"24 4860.78181134244 4494.64064038047 4748.04069226421 4851.66052786926 \n",
"25 7504.85090744898 6885.82968106945 6806.67746673071 7153.44432535212 \n",
"26 13039.1216499582 12157.3082176473 12071.7779871352 11728.7993875108 \n",
"27 NaN NaN NaN NaN \n",
"28 41787.0214028978 41807.6533410575 39151.2342290391 40979.6419433378 \n",
"29 7750.03988003072 7333.35507303945 7656.63850554922 7851.26542804234 \n",
".. ... ... ... ... \n",
"187 59593.6847982389 57134.0770682404 60283.24522267 58899.9797944845 \n",
"188 88002.6095703805 83208.68654235 84669.2929367996 85610.8420285261 \n",
"189 NaN NaN NaN NaN \n",
"190 841.219870374428 962.439124853526 1048.66690599689 1113.36635446715 \n",
"191 740.383900829825 827.52888076909 909.330141239446 954.618987954616 \n",
"192 5539.49436810396 5915.22114668686 6225.05228315387 5969.94011583791 \n",
"193 1015.71592799663 1127.10821457355 1117.73125130819 1131.23085071824 \n",
"194 572.025703222528 573.207476512184 589.014053731293 629.9976439467 \n",
"195 4226.69274653294 4364.30924422214 4117.31098292096 4114.05211511279 \n",
"196 18287.3907851354 18322.323800986 20217.0322820943 21317.449265568 \n",
"197 4291.87604315683 4179.46434367471 4248.89127558615 4328.90419734881 \n",
"198 10538.4351203671 10539.3703371146 10800.3579763053 10303.8988002501 \n",
"199 5724.53710231112 6797.72116602834 7480.32167773692 8193.72029690445 \n",
"200 NaN NaN NaN NaN \n",
"201 3993.50025430234 4044.19378022487 3880.19087861123 3826.90331140252 \n",
"202 591.438623816353 656.398072749334 674.341641819883 714.567356471156 \n",
"203 3569.75702740477 3855.4212801318 3986.28296611562 3065.16422265266 \n",
"204 39901.2209155518 41712.1242109135 42831.0891322689 43962.7136932011 \n",
"205 41020.3769643089 41294.5148008666 42294.8901157814 46278.5202128829 \n",
"206 49781.8006563523 51433.0470904727 52660.2951049798 54398.4600093994 \n",
"207 14166.5576669096 15092.4720586676 16881.38400062 16737.973101175 \n",
"208 1544.82777273524 1719.03619624155 1877.9645118434 2052.58678135925 \n",
"209 3275.02398203673 3158.4209735273 3167.05530330465 3147.96485986836 \n",
"210 10754.5928790654 12771.5950361107 12265.03113567 NaN \n",
"211 1542.67043610149 1754.5479738641 1907.56438167972 2052.31908380089 \n",
"212 NaN NaN NaN NaN \n",
"213 2663.53702496611 2787.16973802917 2992.20099455427 2960.77800405245 \n",
"214 1282.39883187217 1289.03407763668 1408.14619260488 NaN \n",
"215 1635.54730435222 1724.74356387435 1839.52248112115 1725.97454864009 \n",
"216 768.556409302399 850.827696604891 905.500321786172 931.19818468692 \n",
"\n",
" 2015 2016 \n",
"0 590.269515382605 NaN \n",
"1 3965.01680558488 NaN \n",
"2 4206.03123244958 NaN \n",
"3 NaN NaN \n",
"4 NaN NaN \n",
"5 4102.11858969272 NaN \n",
"6 14128.8785463675 NaN \n",
"7 13431.8783398577 NaN \n",
"8 3499.80421759862 NaN \n",
"9 NaN NaN \n",
"10 56327.7214484289 NaN \n",
"11 43438.8630381343 NaN \n",
"12 5496.34464026248 NaN \n",
"13 22896.9236868716 NaN \n",
"14 23395.7476902684 NaN \n",
"15 1211.70153057661 NaN \n",
"16 15660.6794152314 NaN \n",
"17 5740.45649479562 NaN \n",
"18 40231.2831740081 NaN \n",
"19 4906.9406908683 NaN \n",
"20 779.067867757338 NaN \n",
"21 NaN NaN \n",
"22 2532.45446832741 NaN \n",
"23 3095.3596925636 NaN \n",
"24 4197.80730449044 NaN \n",
"25 6360.64477568565 NaN \n",
"26 8538.5899749574 NaN \n",
"27 NaN NaN \n",
"28 36607.9278817468 NaN \n",
"29 6819.86910816324 NaN \n",
".. ... ... \n",
"187 50272.9415019928 NaN \n",
"188 80214.7301520483 NaN \n",
"189 NaN NaN \n",
"190 925.91188767081 NaN \n",
"191 864.857502346707 NaN \n",
"192 5816.44068998475 NaN \n",
"193 1134.42642789183 NaN \n",
"194 547.974683363941 NaN \n",
"195 NaN NaN \n",
"196 20444.0785895112 NaN \n",
"197 3872.51208364171 NaN \n",
"198 9130.02606479616 NaN \n",
"199 6947.84002260404 NaN \n",
"200 NaN NaN \n",
"201 NaN NaN \n",
"202 675.573466220693 NaN \n",
"203 2114.95471628444 NaN \n",
"204 40438.3763627115 NaN \n",
"205 43734.0001709187 NaN \n",
"206 55836.7926308733 NaN \n",
"207 15573.9009189374 NaN \n",
"208 2132.07244181734 NaN \n",
"209 NaN NaN \n",
"210 NaN NaN \n",
"211 2111.13802366815 NaN \n",
"212 NaN NaN \n",
"213 2866.80010121789 NaN \n",
"214 NaN NaN \n",
"215 1307.78861109883 NaN \n",
"216 890.416087751634 NaN \n",
"\n",
"[217 rows x 18 columns]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Merde gdp and code\n",
"country_gdp = pd.merge(country_gdp, country_codes, left_on='country_code_3', right_on='ISO3166-1-Alpha-3', how='left')\n",
"country_gdp.drop(['official_name_en', 'ISO3166-1-Alpha-3', 'country_code_3'], axis=1, inplace=True)\n",
"country_gdp = country_gdp.rename(columns = {'ISO3166-1-Alpha-2':'country_code',\n",
" 'ISO4217-currency_alphabetic_code':'currency_code'})\n",
"country_gdp.replace('..', np.nan, inplace=True)\n",
"\n",
"# Reorder columns\n",
"cols = list(country_gdp.columns)\n",
"cols.insert(1, cols.pop(cols.index('country_code')))\n",
"cols.insert(2, cols.pop(cols.index('currency_code')))\n",
"country_gdp = country_gdp.reindex(columns= cols)\n",
"\n",
"country_gdp"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def gdp(country_code, disbursal_date):\n",
" def historical_gdp(array):\n",
" array = np.array(map(float, array))\n",
" array = array[~np.isnan(array)] # Remove NaN\n",
" if len(array) == 0: # No GDP values\n",
" return 0\n",
" return float(np.mean(array, dtype=np.float64))\n",
" \n",
" # TODO: Unable to resolve country code WorldBank dataset has wrong alpha 3 codes e.g. Andorra causing issues\n",
" try:\n",
" float(country_code)\n",
" return 0\n",
" except:\n",
" if country_code not in list(country_gdp['country_code']):\n",
" return 0 # TODO: Bad solution ? \n",
" \n",
" # Get the historical average GDP if no disbursal date\n",
" all_gdp = country_gdp[country_gdp.country_code == country_code].values[0][3:]\n",
" if (disbursal_date is None): # or (country_gdp[date][country_gdp.country_code == country_code] == float('Nan')):\n",
" return historical_gdp(all_gdp)\n",
" \n",
" date = str(datetime.strptime(disbursal_date, '%Y-%m-%dT%H:%M:%SZ').year)\n",
" # Get the historical average GDP if no GDP for that year\n",
" if pd.isnull(country_gdp[date][country_gdp.country_code == country_code].values[0]):\n",
" return historical_gdp(all_gdp)\n",
" \n",
" return float(country_gdp[date][country_gdp.country_code == country_code].values[0])\n",
"\n",
"sql_ctx.registerFunction('gdp', gdp, pyspark.sql.types.FloatType())\n",
"# gdp('ZA', '2016-12-13T18:22:55Z')\n",
"\n",
"# sql_ctx.sql(\"\"\"\n",
"# SELECT \n",
"# activity, \n",
"# basket_amount,\n",
"# terms.disbursal_date,\n",
"# gdp(location.country_code, terms.disbursal_date) as gdp\n",
"# FROM loans\n",
"# LIMIT 10\n",
"# \"\"\").collect()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"train, validation, test = loans.randomSplit([.6, .2, .2], 101)\n",
"\n",
"\n",
"train.registerTempTable('loans_train')\n",
"validation.registerTempTable('loans_validation')\n",
"test.registerTempTable('loans_test')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Starts Here - Currency exchange"
]
},
{
"cell_type": "code",
"execution_count": 23,
"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>Series Name</th>\n",
" <th>Series Code</th>\n",
" <th>Country Name</th>\n",
" <th>Country Code</th>\n",
" <th>2002 [YR2002]</th>\n",
" <th>2003 [YR2003]</th>\n",
" <th>2004 [YR2004]</th>\n",
" <th>2005 [YR2005]</th>\n",
" <th>2006 [YR2006]</th>\n",
" <th>2007 [YR2007]</th>\n",
" <th>2008 [YR2008]</th>\n",
" <th>2009 [YR2009]</th>\n",
" <th>2010 [YR2010]</th>\n",
" <th>2011 [YR2011]</th>\n",
" <th>2012 [YR2012]</th>\n",
" <th>2013 [YR2013]</th>\n",
" <th>2014 [YR2014]</th>\n",
" <th>2015 [YR2015]</th>\n",
" <th>2016 [YR2016]</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>213</th>\n",
" <td>Official exchange rate (LCU per US$, period av...</td>\n",
" <td>PA.NUS.FCRF</td>\n",
" <td>West Bank and Gaza</td>\n",
" <td>WBG</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>214</th>\n",
" <td>Official exchange rate (LCU per US$, period av...</td>\n",
" <td>PA.NUS.FCRF</td>\n",
" <td>Yemen, Rep.</td>\n",
" <td>YEM</td>\n",
" <td>175.625</td>\n",
" <td>183.448333333333</td>\n",
" <td>184.775833333333</td>\n",
" <td>191.509166666667</td>\n",
" <td>197.049166666667</td>\n",
" <td>198.953333333333</td>\n",
" <td>199.764166666667</td>\n",
" <td>202.846666666667</td>\n",
" <td>219.59</td>\n",
" <td>213.8</td>\n",
" <td>214.350833333333</td>\n",
" <td>214.89</td>\n",
" <td>214.89</td>\n",
" <td>214.89</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>215</th>\n",
" <td>Official exchange rate (LCU per US$, period av...</td>\n",
" <td>PA.NUS.FCRF</td>\n",
" <td>Zambia</td>\n",
" <td>ZMB</td>\n",
" <td>4.398595</td>\n",
" <td>4.73327104649872</td>\n",
" <td>4.77887538643579</td>\n",
" <td>4.46350331051587</td>\n",
" <td>3.60307204258249</td>\n",
" <td>4.00252266503643</td>\n",
" <td>3.74566069008764</td>\n",
" <td>5.04610924521235</td>\n",
" <td>4.797136875</td>\n",
" <td>4.86066553209349</td>\n",
" <td>5.14725266514413</td>\n",
" <td>5.39588706794446</td>\n",
" <td>6.15281624812449</td>\n",
" <td>8.63235596234196</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>216</th>\n",
" <td>Official exchange rate (LCU per US$, period av...</td>\n",
" <td>PA.NUS.FCRF</td>\n",
" <td>Zimbabwe</td>\n",
" <td>ZWE</td>\n",
" <td>0.0550982905810338</td>\n",
" <td>0.698216071305723</td>\n",
" <td>5.07441941463195</td>\n",
" <td>22.3890396048255</td>\n",
" <td>164.547356500646</td>\n",
" <td>9686.77166954175</td>\n",
" <td>6723052073.3381</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" <td>..</td>\n",
" </tr>\n",
" <tr>\n",
" <th>217</th>\n",
" <td>Official exchange rate (LCU per US$, period av...</td>\n",
" <td>PA.NUS.FCRF</td>\n",
" <td>Euro area</td>\n",
" <td>EMU</td>\n",
" <td>1.06255166666667</td>\n",
" <td>0.886034166666667</td>\n",
" <td>0.805365</td>\n",
" <td>0.80412</td>\n",
" <td>0.797140833333333</td>\n",
" <td>0.7306375</td>\n",
" <td>0.682674711239873</td>\n",
" <td>0.719843359785615</td>\n",
" <td>0.755044951989835</td>\n",
" <td>0.719355253609154</td>\n",
" <td>0.778293601412852</td>\n",
" <td>0.75315918184727</td>\n",
" <td>0.753730736717402</td>\n",
" <td>0.901658961641278</td>\n",
" <td>..</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Series Name Series Code \\\n",
"213 Official exchange rate (LCU per US$, period av... PA.NUS.FCRF \n",
"214 Official exchange rate (LCU per US$, period av... PA.NUS.FCRF \n",
"215 Official exchange rate (LCU per US$, period av... PA.NUS.FCRF \n",
"216 Official exchange rate (LCU per US$, period av... PA.NUS.FCRF \n",
"217 Official exchange rate (LCU per US$, period av... PA.NUS.FCRF \n",
"\n",
" Country Name Country Code 2002 [YR2002] 2003 [YR2003] \\\n",
"213 West Bank and Gaza WBG .. .. \n",
"214 Yemen, Rep. YEM 175.625 183.448333333333 \n",
"215 Zambia ZMB 4.398595 4.73327104649872 \n",
"216 Zimbabwe ZWE 0.0550982905810338 0.698216071305723 \n",
"217 Euro area EMU 1.06255166666667 0.886034166666667 \n",
"\n",
" 2004 [YR2004] 2005 [YR2005] 2006 [YR2006] 2007 [YR2007] \\\n",
"213 .. .. .. .. \n",
"214 184.775833333333 191.509166666667 197.049166666667 198.953333333333 \n",
"215 4.77887538643579 4.46350331051587 3.60307204258249 4.00252266503643 \n",
"216 5.07441941463195 22.3890396048255 164.547356500646 9686.77166954175 \n",
"217 0.805365 0.80412 0.797140833333333 0.7306375 \n",
"\n",
" 2008 [YR2008] 2009 [YR2009] 2010 [YR2010] \\\n",
"213 .. .. .. \n",
"214 199.764166666667 202.846666666667 219.59 \n",
"215 3.74566069008764 5.04610924521235 4.797136875 \n",
"216 6723052073.3381 .. .. \n",
"217 0.682674711239873 0.719843359785615 0.755044951989835 \n",
"\n",
" 2011 [YR2011] 2012 [YR2012] 2013 [YR2013] \\\n",
"213 .. .. .. \n",
"214 213.8 214.350833333333 214.89 \n",
"215 4.86066553209349 5.14725266514413 5.39588706794446 \n",
"216 .. .. .. \n",
"217 0.719355253609154 0.778293601412852 0.75315918184727 \n",
"\n",
" 2014 [YR2014] 2015 [YR2015] 2016 [YR2016] \n",
"213 .. .. .. \n",
"214 214.89 214.89 .. \n",
"215 6.15281624812449 8.63235596234196 .. \n",
"216 .. .. .. \n",
"217 0.753730736717402 0.901658961641278 .. "
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"currencies_raw = pd.read_csv(LOCAL_PATH + 'economic-data/currencies.csv')\n",
"currencies_raw.tail()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Cleanup\n",
"currencies = currencies_raw.drop(country_gdp_raw.columns[[0, 1]], axis=1)\n",
"currencies.columns = ['country_name', 'country_code_3', '2002', '2003', '2004', '2005', '2006',\n",
" '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016']"
]
},
{
"cell_type": "code",
"execution_count": 25,
"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>country_name</th>\n",
" <th>country_code</th>\n",
" <th>currency_code</th>\n",
" <th>2002</th>\n",
" <th>2003</th>\n",
" <th>2004</th>\n",
" <th>2005</th>\n",
" <th>2006</th>\n",
" <th>2007</th>\n",
" <th>2008</th>\n",
" <th>2009</th>\n",
" <th>2010</th>\n",
" <th>2011</th>\n",
" <th>2012</th>\n",
" <th>2013</th>\n",
" <th>2014</th>\n",
" <th>2015</th>\n",
" <th>2016</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>213</th>\n",
" <td>West Bank and Gaza</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>214</th>\n",
" <td>Yemen, Rep.</td>\n",
" <td>YE</td>\n",
" <td>YER</td>\n",
" <td>175.625</td>\n",
" <td>183.448333333333</td>\n",
" <td>184.775833333333</td>\n",
" <td>191.509166666667</td>\n",
" <td>197.049166666667</td>\n",
" <td>198.953333333333</td>\n",
" <td>199.764166666667</td>\n",
" <td>202.846666666667</td>\n",
" <td>219.59</td>\n",
" <td>213.8</td>\n",
" <td>214.350833333333</td>\n",
" <td>214.89</td>\n",
" <td>214.89</td>\n",
" <td>214.89</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>215</th>\n",
" <td>Zambia</td>\n",
" <td>ZM</td>\n",
" <td>ZMW</td>\n",
" <td>4.398595</td>\n",
" <td>4.73327104649872</td>\n",
" <td>4.77887538643579</td>\n",
" <td>4.46350331051587</td>\n",
" <td>3.60307204258249</td>\n",
" <td>4.00252266503643</td>\n",
" <td>3.74566069008764</td>\n",
" <td>5.04610924521235</td>\n",
" <td>4.797136875</td>\n",
" <td>4.86066553209349</td>\n",
" <td>5.14725266514413</td>\n",
" <td>5.39588706794446</td>\n",
" <td>6.15281624812449</td>\n",
" <td>8.63235596234196</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>216</th>\n",
" <td>Zimbabwe</td>\n",
" <td>ZW</td>\n",
" <td>ZWL</td>\n",
" <td>0.0550982905810338</td>\n",
" <td>0.698216071305723</td>\n",
" <td>5.07441941463195</td>\n",
" <td>22.3890396048255</td>\n",
" <td>164.547356500646</td>\n",
" <td>9686.77166954175</td>\n",
" <td>6723052073.3381</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>217</th>\n",
" <td>Euro area</td>\n",
" <td>EU</td>\n",
" <td>EMU</td>\n",
" <td>1.06255166666667</td>\n",
" <td>0.886034166666667</td>\n",
" <td>0.805365</td>\n",
" <td>0.80412</td>\n",
" <td>0.797140833333333</td>\n",
" <td>0.7306375</td>\n",
" <td>0.682674711239873</td>\n",
" <td>0.719843359785615</td>\n",
" <td>0.755044951989835</td>\n",
" <td>0.719355253609154</td>\n",
" <td>0.778293601412852</td>\n",
" <td>0.75315918184727</td>\n",
" <td>0.753730736717402</td>\n",
" <td>0.901658961641278</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" country_name country_code currency_code 2002 \\\n",
"213 West Bank and Gaza NaN NaN NaN \n",
"214 Yemen, Rep. YE YER 175.625 \n",
"215 Zambia ZM ZMW 4.398595 \n",
"216 Zimbabwe ZW ZWL 0.0550982905810338 \n",
"217 Euro area EU EMU 1.06255166666667 \n",
"\n",
" 2003 2004 2005 2006 \\\n",
"213 NaN NaN NaN NaN \n",
"214 183.448333333333 184.775833333333 191.509166666667 197.049166666667 \n",
"215 4.73327104649872 4.77887538643579 4.46350331051587 3.60307204258249 \n",
"216 0.698216071305723 5.07441941463195 22.3890396048255 164.547356500646 \n",
"217 0.886034166666667 0.805365 0.80412 0.797140833333333 \n",
"\n",
" 2007 2008 2009 \\\n",
"213 NaN NaN NaN \n",
"214 198.953333333333 199.764166666667 202.846666666667 \n",
"215 4.00252266503643 3.74566069008764 5.04610924521235 \n",
"216 9686.77166954175 6723052073.3381 NaN \n",
"217 0.7306375 0.682674711239873 0.719843359785615 \n",
"\n",
" 2010 2011 2012 \\\n",
"213 NaN NaN NaN \n",
"214 219.59 213.8 214.350833333333 \n",
"215 4.797136875 4.86066553209349 5.14725266514413 \n",
"216 NaN NaN NaN \n",
"217 0.755044951989835 0.719355253609154 0.778293601412852 \n",
"\n",
" 2013 2014 2015 2016 \n",
"213 NaN NaN NaN NaN \n",
"214 214.89 214.89 214.89 NaN \n",
"215 5.39588706794446 6.15281624812449 8.63235596234196 NaN \n",
"216 NaN NaN NaN NaN \n",
"217 0.75315918184727 0.753730736717402 0.901658961641278 NaN "
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get ISO 2 code\n",
"currencies = pd.merge(currencies, country_codes, left_on='country_code_3', right_on='ISO3166-1-Alpha-3', how='left')\n",
"currencies.drop(['official_name_en', 'ISO3166-1-Alpha-3', 'country_code_3'], axis=1, inplace=True)\n",
"currencies = currencies.rename(columns = {'ISO3166-1-Alpha-2':'country_code',\n",
" 'ISO4217-currency_alphabetic_code':'currency_code'})\n",
"currencies.replace('..', np.nan, inplace=True)\n",
"\n",
"# Add code for European Union\n",
"currencies.set_value(217, 'country_code', 'EU')\n",
"currencies.set_value(217, 'currency_code', 'EMU')\n",
"\n",
"# Reorder columns\n",
"cols = list(currencies.columns)\n",
"cols.insert(1, cols.pop(cols.index('country_code')))\n",
"cols.insert(2, cols.pop(cols.index('currency_code')))\n",
"currencies = currencies.reindex(columns=cols)\n",
"\n",
"currencies.tail()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def xchange_rate(country_code, disbursal_date):\n",
" def historical_rates(array):\n",
" array = np.array(map(float, array))\n",
" array = array[~np.isnan(array)] # Remove NaN\n",
" if len(array) == 0: # No rate values\n",
" return 1\n",
" return float(np.mean(array, dtype=np.float64))\n",
" \n",
" eu = ['AT','BE','BG','HR','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE',\n",
" 'IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB']\n",
" us = ['AS','GU','MP','PR','UM','VI']\n",
" try:\n",
" float(country_code) # Country code unknown?\n",
" if pd.isnull(country_code):\n",
" return 1 # TODO: Bad solution ??\n",
" except:\n",
" if country_code in eu:\n",
" country_code = 'EU'\n",
" elif country_code in us:\n",
" country_code = 'US'\n",
" if country_code not in list(currencies['country_code']):\n",
" return 1\n",
" \n",
" \n",
" # TODO: Unable to resolve country code WorldBank dataset has wrong alpha 3 codes e.g. Andorra causing\n",
" try:\n",
" float(country_code)\n",
" return 0\n",
" except:\n",
" if country_code not in list(currencies['country_code']):\n",
" return 0 # TODO: Bad solution \n",
" \n",
" # Get the historical average exchange rate if no disbursal date\n",
" all_rates = currencies[currencies.country_code == country_code].values[0][3:]\n",
" if (disbursal_date is None): # or (country_gdp[date][country_gdp.country_code == country_code] == float('Nan')):\n",
" return historical_rates(all_rates)\n",
" \n",
" date = str(datetime.strptime(disbursal_date, '%Y-%m-%dT%H:%M:%SZ').year)\n",
" # Get the historical average exchange rate if no GDP for that year\n",
" if pd.isnull(currencies[date][currencies.country_code == country_code].values[0]):\n",
" return historical_rates(all_rates)\n",
" \n",
" return float(currencies[date][currencies.country_code == country_code].values[0])\n",
"\n",
"sql_ctx.registerFunction('xchange_rate', xchange_rate, pyspark.sql.types.FloatType())\n",
"# xchange_rate('BE', '2016-12-13T18:22:55Z') \n",
"\n",
"# sql_ctx.sql(\"\"\"\n",
"# SELECT \n",
"# xchange_rate(location.country_code, terms.disbursal_date) as xchange_rate\n",
"# FROM loans\n",
"# LIMIT 20\n",
"# \"\"\").collect()"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def extract_tags(tags):\n",
" value = []\n",
" if len(tags) != 0:\n",
" value = [item for (item,) in tags]\n",
" return ','.join(value)\n",
"\n",
"sql_ctx.registerFunction('extract_tags', extract_tags, pyspark.sql.types.StringType())\n",
"\n",
" \n",
"# # unpack_tags([('volunteer_pick',), ('volunteer_like',)])\n",
"\n",
"# sql_ctx.registerFunction('unpack_tags', unpack_tags)\n",
"# sql_ctx.sql(\n",
"# \"\"\"\n",
"# SELECT \n",
"# unpack_tags(tags) as tags\n",
"# FROM loans\n",
"# LIMIT 20000\n",
"# \"\"\"\n",
"# ).collect()"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"\n",
"query = '''\n",
"SELECT\n",
" id,\n",
" activity,\n",
" size(borrowers) as num_borrowers,\n",
" male_proportion(borrowers) as male_proportion,\n",
" lender_count,\n",
" location.country,\n",
" location.country_code,\n",
" partner_id,\n",
" sector,\n",
" extract_tags(tags) as tags,\n",
" DATEDIFF(terms.disbursal_date, planned_expiration_date) as loan_length,\n",
" terms.disbursal_amount,\n",
" terms.disbursal_currency,\n",
" terms.disbursal_date,\n",
" size(terms.scheduled_payments) as num_repayments,\n",
" terms.repayment_interval,\n",
" CASE WHEN\n",
" (status = 'defaulted') OR\n",
" (status = 'deleted') OR\n",
" (status = 'issue') OR\n",
" (status = 'inactive_expired') OR\n",
" (status = 'expired') OR\n",
" (status = 'inactive') OR\n",
" (delinquent = True) THEN 1 ELSE 0 END AS bad_loan,\n",
" gdp(location.country_code, terms.disbursal_date) as gdp,\n",
" xchange_rate(location.country_code, terms.disbursal_date) as xchange_rate,\n",
" status,\n",
" delinquent\n",
" \n",
"FROM {}\n",
"WHERE\n",
" status != 'fundraising' AND\n",
" status != 'funded'\n",
"'''# Removed CASE WHEN (status = 'refunded') as it appears not to be bad loan indicator\n",
"\n",
"train_filtered = sql_ctx.sql(query.format('loans_train'))\n",
"# sparkSql.sql(query.format('loans_validation')).write.json('validation_data-filtered.json')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Prediction"
]
},
{
"cell_type": "code",
"execution_count": 163,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"loans_pd = sql_ctx.sql(query2.format('loans')).toPandas()"
]
},
{
"cell_type": "code",
"execution_count": 164,
"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>activity</th>\n",
" <th>num_borrowers</th>\n",
" <th>male_proportion</th>\n",
" <th>lender_count</th>\n",
" <th>country</th>\n",
" <th>country_code</th>\n",
" <th>partner_id</th>\n",
" <th>sector</th>\n",
" <th>tags</th>\n",
" <th>...</th>\n",
" <th>disbursal_amount</th>\n",
" <th>disbursal_currency</th>\n",
" <th>disbursal_date</th>\n",
" <th>num_repayments</th>\n",
" <th>repayment_interval</th>\n",
" <th>bad_loan</th>\n",
" <th>gdp</th>\n",
" <th>xchange_rate</th>\n",
" <th>status</th>\n",
" <th>delinquent</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1224</td>\n",
" <td>Clothing Sales</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>Honduras</td>\n",
" <td>HN</td>\n",
" <td>5</td>\n",
" <td>Clothing</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>250.0</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" <td>0</td>\n",
" <td>None</td>\n",
" <td>1</td>\n",
" <td>1884.941162</td>\n",
" <td>18.520081</td>\n",
" <td>deleted</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5320</td>\n",
" <td>Food Production/Sales</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" <td>7</td>\n",
" <td>Ghana</td>\n",
" <td>GH</td>\n",
" <td>19</td>\n",
" <td>Food</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>500.0</td>\n",
" <td>USD</td>\n",
" <td>2007-03-15T04:52:22Z</td>\n",
" <td>9</td>\n",
" <td>Monthly</td>\n",
" <td>0</td>\n",
" <td>1099.022339</td>\n",
" <td>0.935248</td>\n",
" <td>paid</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9416</td>\n",
" <td>Food Production/Sales</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" <td>3</td>\n",
" <td>Vietnam</td>\n",
" <td>VN</td>\n",
" <td>41</td>\n",
" <td>Food</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>75.0</td>\n",
" <td>USD</td>\n",
" <td>2007-05-17T22:02:42Z</td>\n",
" <td>6</td>\n",
" <td>Monthly</td>\n",
" <td>0</td>\n",
" <td>919.209290</td>\n",
" <td>16105.125000</td>\n",
" <td>paid</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>13512</td>\n",
" <td>Clothing Sales</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" <td>10</td>\n",
" <td>Nigeria</td>\n",
" <td>NG</td>\n",
" <td>20</td>\n",
" <td>Clothing</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>450.0</td>\n",
" <td>USD</td>\n",
" <td>2007-07-20T16:35:52Z</td>\n",
" <td>8</td>\n",
" <td>Monthly</td>\n",
" <td>0</td>\n",
" <td>1131.147705</td>\n",
" <td>125.808105</td>\n",
" <td>paid</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>17608</td>\n",
" <td>Livestock</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" <td>36</td>\n",
" <td>Cote D'Ivoire</td>\n",
" <td>CI</td>\n",
" <td>53</td>\n",
" <td>Agriculture</td>\n",
" <td></td>\n",
" <td>...</td>\n",
" <td>950.0</td>\n",
" <td>USD</td>\n",
" <td>2007-09-20T02:55:18Z</td>\n",
" <td>12</td>\n",
" <td>Monthly</td>\n",
" <td>0</td>\n",
" <td>1078.541504</td>\n",
" <td>479.266785</td>\n",
" <td>paid</td>\n",
" <td>None</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" id activity num_borrowers male_proportion lender_count \\\n",
"0 1224 Clothing Sales 1 0.0 0 \n",
"1 5320 Food Production/Sales 1 0.0 7 \n",
"2 9416 Food Production/Sales 1 0.0 3 \n",
"3 13512 Clothing Sales 1 0.0 10 \n",
"4 17608 Livestock 1 0.0 36 \n",
"\n",
" country country_code partner_id sector tags ... \\\n",
"0 Honduras HN 5 Clothing ... \n",
"1 Ghana GH 19 Food ... \n",
"2 Vietnam VN 41 Food ... \n",
"3 Nigeria NG 20 Clothing ... \n",
"4 Cote D'Ivoire CI 53 Agriculture ... \n",
"\n",
" disbursal_amount disbursal_currency disbursal_date num_repayments \\\n",
"0 250.0 None None 0 \n",
"1 500.0 USD 2007-03-15T04:52:22Z 9 \n",
"2 75.0 USD 2007-05-17T22:02:42Z 6 \n",
"3 450.0 USD 2007-07-20T16:35:52Z 8 \n",
"4 950.0 USD 2007-09-20T02:55:18Z 12 \n",
"\n",
" repayment_interval bad_loan gdp xchange_rate status delinquent \n",
"0 None 1 1884.941162 18.520081 deleted None \n",
"1 Monthly 0 1099.022339 0.935248 paid None \n",
"2 Monthly 0 919.209290 16105.125000 paid None \n",
"3 Monthly 0 1131.147705 125.808105 paid None \n",
"4 Monthly 0 1078.541504 479.266785 paid None \n",
"\n",
"[5 rows x 21 columns]"
]
},
"execution_count": 164,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loans_pd.head()"
]
},
{
"cell_type": "code",
"execution_count": 165,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"\n",
"loans_pd.fillna(0, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 166,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"loans_pd = loans_pd.drop(['status', 'delinquent'], axis=1)\n",
"loans_dummies = pd.get_dummies(loans_pd)\n",
"\n",
"train, test = train_test_split(loans_dummies, test_size=0.30, random_state=42)"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"11 0\n",
"47 0\n",
"85 0\n",
"28 1\n",
"93 1\n",
"Name: bad_loan, dtype: int64"
]
},
"execution_count": 168,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_target = pd.Series(train['bad_loan'])\n",
"train_ids = pd.Series(test['id'])\n",
"\n",
"test_target = pd.Series(test['bad_loan'])\n",
"test_ids = pd.Series(test['id'])\n",
"\n",
"train = train.drop(['id', 'bad_loan'], axis=1)\n",
"test = test.drop(['id', 'bad_loan'], axis=1)\n",
"\n",
"train_target.head()"
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"train_data = train.as_matrix()\n",
"test_data = test.as_matrix()"
]
},
{
"cell_type": "code",
"execution_count": 172,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from sklearn import svm\n",
"\n",
"clf = svm.SVC(gamma=0.001, C=100.)"
]
},
{
"cell_type": "code",
"execution_count": 173,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.93333333333333335"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"clf.fit(train_data, train_target)\n",
"\n",
"predicted = clf.predict(test_data)\n",
"np.mean(predicted == test_target)"
]
},
{
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}