{ "metadata": { "name": "", "signature": "sha256:5f2f813e4f9aed61dcbe0eb1c90644185a05a33a9c43b04c225f78b0a41c2333" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "World Bank Indicators Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook provides a brief demonstration of how to access the World Bank Indicators data using `pandas`.\n", "\n", "A wrapper for the API is provided as part of the main `pandas` distribution, as part of the [Remote Data Access](http://pandas.pydata.org/pandas-docs/stable/remote_data.html) support." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#First of all we need to load in the pandas library...\n", "import pandas as pd\n", "\n", "#...and the pandas remote data access support for calls to the World Bank Indicators API\n", "from pandas.io import wb" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Searching for Indicators" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The easiest way to identify an indicator is to search for it by name using a keyword or key phrase." ] }, { "cell_type": "code", "collapsed": false, "input": [ "wb.search('fertility rate')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamesourcesourceNotesourceOrganizationtopics
6554 SP.ADO.TFRT Adolescent fertility rate (births per 1,000 wo... World Development Indicators Adolescent fertility rate is the number of bir... b'United Nations Population Division, World Po... Social Development ; Health ; Gender
6594 SP.DYN.TFRT.IN Fertility rate, total (births per woman) World Development Indicators Total fertility rate represents the number of ... b'(1) United Nations Population Division. Worl... Gender ; Health
6595 SP.DYN.TFRT.Q1 Total fertility rate (TFR) (births per woman)... Health Nutrition and Population Statistics by ... Total fertility rate (TFR): The number of chil... b'Household Surveys (DHS, MICS)' Health
6596 SP.DYN.TFRT.Q2 Total fertility rate (TFR) (births per woman)... Health Nutrition and Population Statistics by ... Total fertility rate (TFR): The number of chil... b'Household Surveys (DHS, MICS)' Health
6597 SP.DYN.TFRT.Q3 Total fertility rate (TFR) (births per woman)... Health Nutrition and Population Statistics by ... Total fertility rate (TFR): The number of chil... b'Household Surveys (DHS, MICS)' Health
6598 SP.DYN.TFRT.Q4 Total fertility rate (TFR) (births per woman)... Health Nutrition and Population Statistics by ... Total fertility rate (TFR): The number of chil... b'Household Surveys (DHS, MICS)' Health
6599 SP.DYN.TFRT.Q5 Total fertility rate (TFR) (births per woman)... Health Nutrition and Population Statistics by ... Total fertility rate (TFR): The number of chil... b'Household Surveys (DHS, MICS)' Health
6602 SP.DYN.WFRT Wanted fertility rate (births per woman) World Development Indicators Wanted fertility rate is an estimate of what t... b'Demographic and Health Surveys by ICF Intern... Health ; Gender
6603 SP.DYN.WFRT.Q1 Total wanted fertility rate (births per woman)... Health Nutrition and Population Statistics by ... Total wanted fertility rate: Total wanted fert... b'Household Surveys (DHS, MICS)' Health
6604 SP.DYN.WFRT.Q2 Total wanted fertility rate (births per woman)... Health Nutrition and Population Statistics by ... Total wanted fertility rate: Total wanted fert... b'Household Surveys (DHS, MICS)' Health
6605 SP.DYN.WFRT.Q3 Total wanted fertility rate (births per woman)... Health Nutrition and Population Statistics by ... Total wanted fertility rate: Total wanted fert... b'Household Surveys (DHS, MICS)' Health
6606 SP.DYN.WFRT.Q4 Total wanted fertility rate (births per woman)... Health Nutrition and Population Statistics by ... Total wanted fertility rate: Total wanted fert... b'Household Surveys (DHS, MICS)' Health
6607 SP.DYN.WFRT.Q5 Total wanted fertility rate (births per woman)... Health Nutrition and Population Statistics by ... Total wanted fertility rate: Total wanted fert... b'Household Surveys (DHS, MICS)' Health
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 46, "text": [ " id name \\\n", "6554 SP.ADO.TFRT Adolescent fertility rate (births per 1,000 wo... \n", "6594 SP.DYN.TFRT.IN Fertility rate, total (births per woman) \n", "6595 SP.DYN.TFRT.Q1 Total fertility rate (TFR) (births per woman)... \n", "6596 SP.DYN.TFRT.Q2 Total fertility rate (TFR) (births per woman)... \n", "6597 SP.DYN.TFRT.Q3 Total fertility rate (TFR) (births per woman)... \n", "6598 SP.DYN.TFRT.Q4 Total fertility rate (TFR) (births per woman)... \n", "6599 SP.DYN.TFRT.Q5 Total fertility rate (TFR) (births per woman)... \n", "6602 SP.DYN.WFRT Wanted fertility rate (births per woman) \n", "6603 SP.DYN.WFRT.Q1 Total wanted fertility rate (births per woman)... \n", "6604 SP.DYN.WFRT.Q2 Total wanted fertility rate (births per woman)... \n", "6605 SP.DYN.WFRT.Q3 Total wanted fertility rate (births per woman)... \n", "6606 SP.DYN.WFRT.Q4 Total wanted fertility rate (births per woman)... \n", "6607 SP.DYN.WFRT.Q5 Total wanted fertility rate (births per woman)... \n", "\n", " source \\\n", "6554 World Development Indicators \n", "6594 World Development Indicators \n", "6595 Health Nutrition and Population Statistics by ... \n", "6596 Health Nutrition and Population Statistics by ... \n", "6597 Health Nutrition and Population Statistics by ... \n", "6598 Health Nutrition and Population Statistics by ... \n", "6599 Health Nutrition and Population Statistics by ... \n", "6602 World Development Indicators \n", "6603 Health Nutrition and Population Statistics by ... \n", "6604 Health Nutrition and Population Statistics by ... \n", "6605 Health Nutrition and Population Statistics by ... \n", "6606 Health Nutrition and Population Statistics by ... \n", "6607 Health Nutrition and Population Statistics by ... \n", "\n", " sourceNote \\\n", "6554 Adolescent fertility rate is the number of bir... \n", "6594 Total fertility rate represents the number of ... \n", "6595 Total fertility rate (TFR): The number of chil... \n", "6596 Total fertility rate (TFR): The number of chil... \n", "6597 Total fertility rate (TFR): The number of chil... \n", "6598 Total fertility rate (TFR): The number of chil... \n", "6599 Total fertility rate (TFR): The number of chil... \n", "6602 Wanted fertility rate is an estimate of what t... \n", "6603 Total wanted fertility rate: Total wanted fert... \n", "6604 Total wanted fertility rate: Total wanted fert... \n", "6605 Total wanted fertility rate: Total wanted fert... \n", "6606 Total wanted fertility rate: Total wanted fert... \n", "6607 Total wanted fertility rate: Total wanted fert... \n", "\n", " sourceOrganization \\\n", "6554 b'United Nations Population Division, World Po... \n", "6594 b'(1) United Nations Population Division. Worl... \n", "6595 b'Household Surveys (DHS, MICS)' \n", "6596 b'Household Surveys (DHS, MICS)' \n", "6597 b'Household Surveys (DHS, MICS)' \n", "6598 b'Household Surveys (DHS, MICS)' \n", "6599 b'Household Surveys (DHS, MICS)' \n", "6602 b'Demographic and Health Surveys by ICF Intern... \n", "6603 b'Household Surveys (DHS, MICS)' \n", "6604 b'Household Surveys (DHS, MICS)' \n", "6605 b'Household Surveys (DHS, MICS)' \n", "6606 b'Household Surveys (DHS, MICS)' \n", "6607 b'Household Surveys (DHS, MICS)' \n", "\n", " topics \n", "6554 Social Development ; Health ; Gender \n", "6594 Gender ; Health \n", "6595 Health \n", "6596 Health \n", "6597 Health \n", "6598 Health \n", "6599 Health \n", "6602 Health ; Gender \n", "6603 Health \n", "6604 Health \n", "6605 Health \n", "6606 Health \n", "6607 Health " ] } ], "prompt_number": 46 }, { "cell_type": "code", "collapsed": false, "input": [ "#We can also get a full list of indicators\n", "indicators=wb.get_indicators()\n", "\n", "#Preview first few rows of indicators list\n", "indicators[:5]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamesourcesourceNotesourceOrganizationtopics
0 1.0.HCount.1.25usd Poverty Headcount ($1.25 a day) LAC Equity Lab The poverty headcount index measures the propo... b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty
1 1.0.HCount.10usd Under Middle Class ($10 a day) Headcount LAC Equity Lab The poverty headcount index measures the propo... b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty
2 1.0.HCount.2.5usd Poverty Headcount ($2.50 a day) LAC Equity Lab The poverty headcount index measures the propo... b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty
3 1.0.HCount.Mid10to50 Middle Class ($10-50 a day) Headcount LAC Equity Lab The poverty headcount index measures the propo... b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty
4 1.0.HCount.Ofcl Official Moderate Poverty Rate-National LAC Equity Lab The poverty headcount index measures the propo... b'LAC Equity Lab tabulations of data from Nati... Poverty
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 63, "text": [ " id name \\\n", "0 1.0.HCount.1.25usd Poverty Headcount ($1.25 a day) \n", "1 1.0.HCount.10usd Under Middle Class ($10 a day) Headcount \n", "2 1.0.HCount.2.5usd Poverty Headcount ($2.50 a day) \n", "3 1.0.HCount.Mid10to50 Middle Class ($10-50 a day) Headcount \n", "4 1.0.HCount.Ofcl Official Moderate Poverty Rate-National \n", "\n", " source sourceNote \\\n", "0 LAC Equity Lab The poverty headcount index measures the propo... \n", "1 LAC Equity Lab The poverty headcount index measures the propo... \n", "2 LAC Equity Lab The poverty headcount index measures the propo... \n", "3 LAC Equity Lab The poverty headcount index measures the propo... \n", "4 LAC Equity Lab The poverty headcount index measures the propo... \n", "\n", " sourceOrganization topics \n", "0 b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty \n", "1 b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty \n", "2 b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty \n", "3 b'LAC Equity Lab tabulations of SEDLAC (CEDLAS... Poverty \n", "4 b'LAC Equity Lab tabulations of data from Nati... Poverty " ] } ], "prompt_number": 63 }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you know the identifier - or part of the identifier - for a particular indicator, you can look up details for it directly. Use the * character as a wildcard character." ] }, { "cell_type": "code", "collapsed": false, "input": [ "wb.search('gdp.*capita.*const')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamesourcesourceNotesourceOrganizationtopics
700 6.0.GDPpc_constant GDP per capita, PPP (constant 2011 internation... LAC Equity Lab GDP per capita based on purchasing power parit... b'NULWorld Development Indicators (World Bank)L' Economy & Growth
3496 GDPPCKD GDP per Capita, constant US$, millions GEP Economic Prospects GDP per capita is gross domestic product divid... b'World Bank staff calculations based on World... Economy & Growth
5530 NY.GDP.PCAP.KD GDP per capita (constant 2005 US$) World Development Indicators GDP per capita is gross domestic product divid... b'World Bank national accounts data, and OECD ... Economy & Growth
5532 NY.GDP.PCAP.KN GDP per capita (constant LCU) World Development Indicators GDP per capita is gross domestic product divid... b'World Bank national accounts data, and OECD ... Economy & Growth
5534 NY.GDP.PCAP.PP.KD GDP per capita, PPP (constant 2011 internation... World Development Indicators GDP per capita based on purchasing power parit... b'World Bank, International Comparison Program... Economy & Growth
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 3, "text": [ " id name \\\n", "700 6.0.GDPpc_constant GDP per capita, PPP (constant 2011 internation... \n", "3496 GDPPCKD GDP per Capita, constant US$, millions \n", "5530 NY.GDP.PCAP.KD GDP per capita (constant 2005 US$) \n", "5532 NY.GDP.PCAP.KN GDP per capita (constant LCU) \n", "5534 NY.GDP.PCAP.PP.KD GDP per capita, PPP (constant 2011 internation... \n", "\n", " source \\\n", "700 LAC Equity Lab \n", "3496 GEP Economic Prospects \n", "5530 World Development Indicators \n", "5532 World Development Indicators \n", "5534 World Development Indicators \n", "\n", " sourceNote \\\n", "700 GDP per capita based on purchasing power parit... \n", "3496 GDP per capita is gross domestic product divid... \n", "5530 GDP per capita is gross domestic product divid... \n", "5532 GDP per capita is gross domestic product divid... \n", "5534 GDP per capita based on purchasing power parit... \n", "\n", " sourceOrganization topics \n", "700 b'NULWorld Development Indicators (World Bank)L' Economy & Growth \n", "3496 b'World Bank staff calculations based on World... Economy & Growth \n", "5530 b'World Bank national accounts data, and OECD ... Economy & Growth \n", "5532 b'World Bank national accounts data, and OECD ... Economy & Growth \n", "5534 b'World Bank, International Comparison Program... Economy & Growth " ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Identifying Countries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When retrieving a dataset, we can specifiy which country, countries or regions we want the data for. The locations are identified using the appropriate ISO-2 code. To look up countries we can download the full country list." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#We can get a list of the countries and regions that indicator data may be available for\n", "countries=wb.get_countries()\n", "\n", "#Preview first few rows of countries list\n", "countries[:5]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
adminregioncapitalCityiso3cincomeLeveliso2clatitudelendingTypelongitudenameregion
0 Oranjestad ABW High income: nonOECD AW 12.5167 Not classified -70.0167 Aruba Latin America & Caribbean (all income levels)
1 South Asia Kabul AFG Low income AF 34.5228 IDA 69.1761 Afghanistan South Asia
2 AFR Aggregates A9 Aggregates Africa Aggregates
3 Sub-Saharan Africa (developing only) Luanda AGO Upper middle income AO -8.81155 IBRD 13.242 Angola Sub-Saharan Africa (all income levels)
4 Europe & Central Asia (developing only) Tirane ALB Upper middle income AL 41.3317 IBRD 19.8172 Albania Europe & Central Asia (all income levels)
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 65, "text": [ " adminregion capitalCity iso3c \\\n", "0 Oranjestad ABW \n", "1 South Asia Kabul AFG \n", "2 AFR \n", "3 Sub-Saharan Africa (developing only) Luanda AGO \n", "4 Europe & Central Asia (developing only) Tirane ALB \n", "\n", " incomeLevel iso2c latitude lendingType longitude \\\n", "0 High income: nonOECD AW 12.5167 Not classified -70.0167 \n", "1 Low income AF 34.5228 IDA 69.1761 \n", "2 Aggregates A9 Aggregates \n", "3 Upper middle income AO -8.81155 IBRD 13.242 \n", "4 Upper middle income AL 41.3317 IBRD 19.8172 \n", "\n", " name region \n", "0 Aruba Latin America & Caribbean (all income levels) \n", "1 Afghanistan South Asia \n", "2 Africa Aggregates \n", "3 Angola Sub-Saharan Africa (all income levels) \n", "4 Albania Europe & Central Asia (all income levels) " ] } ], "prompt_number": 65 }, { "cell_type": "code", "collapsed": false, "input": [ "#pandas dataframes allow us to search within the country list for a particular country\n", "countries[ countries['name'] == 'Angola' ]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
adminregioncapitalCityiso3cincomeLeveliso2clatitudelendingTypelongitudenameregion
3 Sub-Saharan Africa (developing only) Luanda AGO Upper middle income AO -8.81155 IBRD 13.242 Angola Sub-Saharan Africa (all income levels)
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 69, "text": [ " adminregion capitalCity iso3c \\\n", "3 Sub-Saharan Africa (developing only) Luanda AGO \n", "\n", " incomeLevel iso2c latitude lendingType longitude name \\\n", "3 Upper middle income AO -8.81155 IBRD 13.242 Angola \n", "\n", " region \n", "3 Sub-Saharan Africa (all income levels) " ] } ], "prompt_number": 69 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Download Data for a Particular Indicator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once you have identified one or more indicators for which you would like to download a dataset, you need to identify the year or range of years, and the country, countries or regions (identified via their ISO-2 code) for which you would like the data." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Download data from the World Bank API into a dataframe\n", "\n", "df = wb.download(\n", " #Use the indicator attribute to identify which indicator or indicators to download\n", " indicator='NY.GDP.PCAP.KD',\n", " #Use the country attribute to identify the countries you want data for\n", " country=['US', 'CA', 'MX'],\n", " #Identify the first year for which you want the data, as an integer or a string\n", " start='2008',\n", " #Identify the last year for which you want the data, as an integer or a string\n", " end=2010\n", " )\n", "\n", "#Show the dataframe \n", "df" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NY.GDP.PCAP.KD
countryyear
Canada2010 36466.815112
2009 35671.659294
2008 37088.020368
Mexico2010 8084.629000
2009 7788.271761
2008 8275.809458
United States2010 43952.436548
2009 43234.451155
2008 44872.653626
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 5, "text": [ " NY.GDP.PCAP.KD\n", "country year \n", "Canada 2010 36466.815112\n", " 2009 35671.659294\n", " 2008 37088.020368\n", "Mexico 2010 8084.629000\n", " 2009 7788.271761\n", " 2008 8275.809458\n", "United States 2010 43952.436548\n", " 2009 43234.451155\n", " 2008 44872.653626" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "#To download data for multiple indicators, specify them as a list\n", "wb.download( indicator=['SP.DYN.TFRT.IN','NY.GDP.PCAP.KD'], country=['US','GB'], start=2008, end=2010 )" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SP.DYN.TFRT.INNY.GDP.PCAP.KD
countryyear
United Kingdom2010 1.920 37600.293399
2009 1.890 37277.481537
2008 1.910 39608.431481
United States2010 1.931 43952.436548
2009 2.002 43234.451155
2008 2.072 44872.653626
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 60, "text": [ " SP.DYN.TFRT.IN NY.GDP.PCAP.KD\n", "country year \n", "United Kingdom 2010 1.920 37600.293399\n", " 2009 1.890 37277.481537\n", " 2008 1.910 39608.431481\n", "United States 2010 1.931 43952.436548\n", " 2009 2.002 43234.451155\n", " 2008 2.072 44872.653626" ] } ], "prompt_number": 60 }, { "cell_type": "code", "collapsed": false, "input": [ "#We can download data for a single year by setting the start and end dates to the same year\n", "#To download data for a single country, you do not need to specify it as a list\n", "df = wb.download( indicator='NY.GDP.PCAP.KD', country='US', start=2008, end=2008 )\n", "\n", "#Show the dataframe \n", "df" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NY.GDP.PCAP.KD
countryyear
United States2008 44872.653626
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 19, "text": [ " NY.GDP.PCAP.KD\n", "country year \n", "United States 2008 44872.653626" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "#To download the data for all countries, set the country attribute to 'all'\n", "df = wb.download( indicator='SP.DYN.TFRT.IN', country='all', start=2010, end=2010 )\n", "\n", "#Show a preview of the the first few rows of the dataframe \n", "df[:10]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SP.DYN.TFRT.IN
countryyear
Andean Region2010 NaN
Arab World2010 3.297409
Caribbean small states2010 2.224484
Central Europe and the Baltics2010 1.445135
East Asia & Pacific (all income levels)2010 1.817921
East Asia & Pacific (developing only)2010 1.856321
East Asia and the Pacific (IFC classification)2010 NaN
Euro area2010 1.573820
Europe & Central Asia (all income levels)2010 1.723861
Europe & Central Asia (developing only)2010 1.979588
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 53, "text": [ " SP.DYN.TFRT.IN\n", "country year \n", "Andean Region 2010 NaN\n", "Arab World 2010 3.297409\n", "Caribbean small states 2010 2.224484\n", "Central Europe and the Baltics 2010 1.445135\n", "East Asia & Pacific (all income levels) 2010 1.817921\n", "East Asia & Pacific (developing only) 2010 1.856321\n", "East Asia and the Pacific (IFC classification) 2010 NaN\n", "Euro area 2010 1.573820\n", "Europe & Central Asia (all income levels) 2010 1.723861\n", "Europe & Central Asia (developing only) 2010 1.979588" ] } ], "prompt_number": 53 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that selecting *all* countries also pulls indicators back for different regional groupings as well as countries." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Summary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`pandas` support for remote data access makes it easy for us to get data from the World Bank Indicators API into a `pandas` dataframe, where we can start to work with it." ] } ], "metadata": {} } ] }