Getting Data
Let’s get an indicator for pollution.
wbdata.search_indicators("CO2 emissions")
indicators["EN.ATM.CO2E.KT"] = "Pollution"
Let’s also get an indicator for inflation.
wbdata.search_indicators("Inflation, consumer")
indicators["FP.CPI.TOTL.ZG"] = "Inflation"
Each country also has a specific country code. Using wbdata.search_countries(), we can find these codes.
wbdata.search_countries("Japan")
wbdata.search_countries("United States")
wbdata.search_countries("Saudi Arabia")
These three countries are the ones we will look at. Let’s create an array.
countries = ["JPN","USA","SAU"]
All that is left is to decide on the dates we want data for. Let’s set it up to get data starting from 1995.
import datetime
dates = (datetime.datetime(1995, 1, 1), datetime.datetime(2017, 1, 1))
Using wbdata.get_dataframe(), we can get the data we need. What we have to feed in arguments are the indicators, the countries and the dates.
df = wbdata.get_dataframe(indicators, country=countries, data_date=dates)
df
If you do not have experience with pandas, this tutorial should be a helpful quick introduction:
10 Minutes to Pandas
Let’s get rid of any cells that are blank by using dropna(). This returns a dataframe with any rows that have blanks dropped. We can give it the argument inplace=True to make it so that we change the dataframe we call it on.
df.dropna(inplace=True)