#First of all we need to load in the pandas library... import pandas as pd #...and the pandas remote data access support for calls to the World Bank Indicators API from pandas.io import wb wb.search('fertility rate') #We can also get a full list of indicators indicators=wb.get_indicators() #Preview first few rows of indicators list indicators[:5] wb.search('gdp.*capita.*const') #We can get a list of the countries and regions that indicator data may be available for countries=wb.get_countries() #Preview first few rows of countries list countries[:5] #pandas dataframes allow us to search within the country list for a particular country countries[ countries['name'] == 'Angola' ] #Download data from the World Bank API into a dataframe df = wb.download( #Use the indicator attribute to identify which indicator or indicators to download indicator='NY.GDP.PCAP.KD', #Use the country attribute to identify the countries you want data for country=['US', 'CA', 'MX'], #Identify the first year for which you want the data, as an integer or a string start='2008', #Identify the last year for which you want the data, as an integer or a string end=2010 ) #Show the dataframe df #To download data for multiple indicators, specify them as a list wb.download( indicator=['SP.DYN.TFRT.IN','NY.GDP.PCAP.KD'], country=['US','GB'], start=2008, end=2010 ) #We can download data for a single year by setting the start and end dates to the same year #To download data for a single country, you do not need to specify it as a list df = wb.download( indicator='NY.GDP.PCAP.KD', country='US', start=2008, end=2008 ) #Show the dataframe df #To download the data for all countries, set the country attribute to 'all' df = wb.download( indicator='SP.DYN.TFRT.IN', country='all', start=2010, end=2010 ) #Show a preview of the the first few rows of the dataframe df[:10]