bblocks.import_tools.hdr
Tools to import UNDP Human Development Report data.
get_hdr_data returns a dataframe with all HDR data. Use the HDR object to extract and interact with the data
Attributes
Classes
An object to help download and use UNDP Human Development Report data |
Functions
|
Parses html for data and metadata links |
|
returns links for data and metadata |
|
Read UNDP Human Development Report data from a URL. |
|
Create a dictionary of variable codes and names. |
|
Format HDR data. |
|
Get UNDP Human Development Report data. |
|
See available indicators |
|
See available composite indices |
Module Contents
- bblocks.import_tools.hdr.BASE_URL: str = 'https://hdr.undp.org/data-center/documentation-and-downloads'
- bblocks.import_tools.hdr.HDR_INDICATORS: dict[str, list]
- bblocks.import_tools.hdr._parse_html(soup: bs4.BeautifulSoup) tuple[str, str]
Parses html for data and metadata links
- bblocks.import_tools.hdr.get_data_links() dict[str, str]
returns links for data and metadata
- bblocks.import_tools.hdr.read_data(response: requests.Response) pandas.DataFrame
Read UNDP Human Development Report data from a URL.
Returns a dataframe with either the data or metadata. The function checks the content type of the response and returns the appropriate dataframe.
- Parameters:
response – Response object from a request to a UNDP HDR data URL.
- bblocks.import_tools.hdr.create_code_dict(metadata_df: pandas.DataFrame) dict[str, str]
Create a dictionary of variable codes and names.
This function takes the metadata dataframe and returns a dictionary to be used to map variable codes to variable names.
- Parameters:
metadata_df (pd.DataFrame) – Metadata dataframe.
- bblocks.import_tools.hdr.format_data(data_df: pandas.DataFrame, code_dict: dict[str, str]) pandas.DataFrame
Format HDR data.
This function takes the raw dataframe and: - melts the data to long format - creates a year columnand new variable column by splitting on the last underscore
(variables contain year such as “hdi_rank_2019”)
creates a variable_name column by mapping the variable to the code_dict
- Parameters:
data_df (pd.DataFrame) – Raw dataframe to be formatted.
code_dict (dict) – Dictionary of variable codes and names.
- bblocks.import_tools.hdr.get_hdr_data() pandas.DataFrame
Get UNDP Human Development Report data.
This function returns the formatted HDR data as a dataframe.
- bblocks.import_tools.hdr.available_indicators(composite_index: str = 'all') list[str]
See available indicators
- Parameters:
composite_index (str) – Composite index to see available indicators for. If None, all
- bblocks.import_tools.hdr.available_composite_indices() list[str]
See available composite indices
- class bblocks.import_tools.hdr.HDR
Bases:
bblocks.import_tools.common.ImportDataAn object to help download and use UNDP Human Development Report data To use, create an instance of the class. Call load_data to load the data for desired indicators. If the data is not already downloaded, it will be downloaded, then the selected indicators will be loaded to the object. To see available indicators, call the function available_indicators. To see available composite indices, call the function available_composite_indices. To get the data as a dataframe, call get_data method. You can force an update by calling update_data
- load_data(indicators: str | list = 'all') bblocks.import_tools.common.ImportData
Load data to the object
When called this method checks if the data has been downloaded, if not it downloads it. It then loads the data into the object for selected indicators and returns the object.
- Parameters:
indicators – Indicator(s) to load. If “all”, load all indicators.
- Returns:
same object with loaded indicators to allow chaining
- update_data(reload_data: bool = True) bblocks.import_tools.common.ImportData
Update the data
When called it will update the data used to load indicators.
- Parameters:
reload_data – If True, reload the indicators after updating the data. Default is True.
- Returns:
same object with updated data to allow chaining