The World Bank is an organization that provides financial advice and helps various nations in terms of their economical state. It also provides a variety of data, including time series, geospatial, financial data, and so on, all of which will be helpful for analysis.
Before we start fetching data from the World Bank website, we must sign up to it. This allows us to get the indicator code for the dataset that we want to download. Signing up for the World Bank is free and doesn't take much time.
For the purpose of this example, I have used the World Development Indicators dataset. You can choose any dataset of your choice and start working on it:
from pandas_datareader import wb
To get the indicator code, select the Databank tab and choose Metadata Glossary from the list that's displayed on the left-hand pane. You can find the indicator below each dataset, on the left-hand side of the panel (marked in red in the attached screenshot):
dat = wb.download(indicator='FP.CPI.TOTL.ZG', start=2005, end=2019)
The DataFrame is returned in a multi-index row format:
dat.head()
This results in the following output:
Now, let's display the data for one particular country, like so:
dat.loc['Canada']
This results in the following output:
We can also return the price inflation data related to only one particular year for a particular country, like so:
dat.loc['Canada'].loc['2015']
This results in the following output: