bblocks.import_tools.world_bank
Attributes
Classes
An object to help download data from the World Bank. |
|
An object to help download _data from World Bank Pink sheets. |
Functions
|
Get _data for an indicator, using wbgapi |
|
Clean Pink Sheet price _data |
|
Clean Pink Sheet Index index _data |
|
Extracts and cleans _data from the pink sheet excel file |
Module Contents
- bblocks.import_tools.world_bank.PINK_SHEET_URL = 'https://thedocs.worldbank.org/en/doc/5d903e848db1d1b83e0ec8f744e55570-0350012021/related/CMO-His...
- bblocks.import_tools.world_bank._get_wb_data(indicator: str, db: int, start_year: int | None = None, end_year: int | None = None, most_recent_only: bool = False) pandas.DataFrame
Get _data for an indicator, using wbgapi
- class bblocks.import_tools.world_bank.WorldBankData
Bases:
bblocks.import_tools.common.ImportDataAn object to help download data from the World Bank. In order to use, create an instance of this class. Then, call the load_indicator method to load an indicator. This can be done multiple times. If the _data for an indicator has never been downloaded, it will be downloaded. If it has been downloaded, it will be loaded from disk. If update_data is set to True when creating the object, the _data will be updated from the World Bank for each indicator. You can force an update by calling update if you want to refresh the _data stored on disk. You can get a dataframe of the _data by calling get_data.
- _indicators: dict[str, tuple[pandas.DataFrame, dict]]
- load_data(indicator: str | list[str], start_year: int | None = None, end_year: int | None = None, most_recent_only: bool = False, db: int = 2, **kwargs) WorldBankData
Get an indicator from the World Bank API
- Parameters:
indicator – the code from the World Bank data portal (e.g. “SP.POP.TOTL”)
start_year – The first year to include in the data
end_year – The last year to include in the data
most_recent_only – If True, only get the most recent non-empty value for each country
db – The database to use. By default, use the WDI database (2)
- Returns:
The same object to allow chaining
- update_data(reload_data: bool = True) bblocks.import_tools.common.ImportData
Update the _data saved on disk for the different indicators
When called, it will go through each indicator and update the _data saved based on the parameters passed to load_indicator.
- Returns:
The same object to allow chaining
- get_data(indicators: str | list = 'all', **kwargs) pandas.DataFrame
- bblocks.import_tools.world_bank.clean_prices(df: pandas.DataFrame) pandas.DataFrame
Clean Pink Sheet price _data
- bblocks.import_tools.world_bank.clean_index(df: pandas.DataFrame) pandas.DataFrame
Clean Pink Sheet Index index _data
- bblocks.import_tools.world_bank.read_pink_sheet(indicator: str) pandas.DataFrame
Extracts and cleans _data from the pink sheet excel file
- Parameters:
indicator – the indicator to extract from the pink sheet. Either “prices” or “index”
- Returns:
A clean pandas DataFrame with the _data
- class bblocks.import_tools.world_bank.PinkSheet
Bases:
bblocks.import_tools.common.ImportDataAn object to help download _data from World Bank Pink sheets.
In order to use, create an instance of this class, specifying the sheet name - ‘Monthly Prices’, ‘Monthly Indices’. Then, call the load_indicator method to load an indicator, optionally specifying in indicator or list of indicators. This can be done multiple times. If the _data has never been downloaded, it will be downloaded. If it has been downloaded, it will be loaded from disk. If update_data is set to True when creating the object, the full dataset will be downloaded to disk when load_indicator is called for the first time. You can force an update by calling update if you want to refresh the data stored on disk. You can get a dataframe of the data by calling get_data
- load_data(indicator: str = 'prices') bblocks.import_tools.common.ImportData
- Load data for an indicator or list of indicators.
- Args:
indicator: The indicator to load. Choose from ‘prices’ or ‘indices’. Default is ‘prices’
- Returns:
The same object to allow chaining
- update_data(reload_data: bool = True) bblocks.import_tools.common.ImportData
Update the _data saved on disk
When called it downloads Pink sheet Data from the World Bank and saves it to disk. Optionally specify whether to reload the _data to the object
- Returns:
The same object to allow chaining