bblocks.import_tools.unaids
Tools to retrieve data from UNAIDS
Attributes
Classes
An object to extract data from UNAIDS. |
Functions
|
returns a json response from UNAIDS |
|
parses data table in json response and returns a formatted dataframe |
|
parses global data in json response and returns a formatted dataframe |
|
cleans dataframe and returns a formatted dataframe |
|
returns the category for an indicator |
|
checks if response has data |
|
returns the dimensions for an indicator |
|
returns the years for an indicator |
|
Returns a list of parameters to be used in the response |
|
Convert response to dataframe |
|
pipeline to extract data |
|
Checks if data is already downloaded for an indicator and area grouping |
|
Checks if area grouping is valid and returns a list of area codes |
Module Contents
- bblocks.import_tools.unaids.URL: str = 'https://aidsinfo.unaids.org/datasheetdatarequest'
- bblocks.import_tools.unaids.AREA_CODES: dict
- bblocks.import_tools.unaids.AVAILABLE_INDICATORS
- bblocks.import_tools.unaids.get_response(url: str, indicator: str, category: str, area_name: str, area_code: str) dict
returns a json response from UNAIDS
- bblocks.import_tools.unaids.parse_data_table(response: dict, dimensions: list, years: list) pandas.DataFrame
parses data table in json response and returns a formatted dataframe
- bblocks.import_tools.unaids.parse_global_data(response: dict, dimensions: list, years: list) pandas.DataFrame
parses global data in json response and returns a formatted dataframe
- bblocks.import_tools.unaids.clean_data(df: pandas.DataFrame, indicator: str) pandas.DataFrame
cleans dataframe and returns a formatted dataframe
- bblocks.import_tools.unaids.get_category(indicator: str) str
returns the category for an indicator
- bblocks.import_tools.unaids.check_response(response: dict) None
checks if response has data
- bblocks.import_tools.unaids.get_dimensions(response: dict) list
returns the dimensions for an indicator
- bblocks.import_tools.unaids.get_years(response: dict) list
returns the years for an indicator
- bblocks.import_tools.unaids.response_params(group: str, indicator: str)
Returns a list of parameters to be used in the response
- bblocks.import_tools.unaids.response_to_df(grouping: str, response: dict, indicator: str) pandas.DataFrame
Convert response to dataframe
- bblocks.import_tools.unaids.extract_data(indicator: str, grouping: str)
pipeline to extract data
- bblocks.import_tools.unaids.check_if_not_downloaded(indicator: str, area_grouping: str) bool
Checks if data is already downloaded for an indicator and area grouping
- Returns:
True if data is not downloaded, False if data is downloaded
- bblocks.import_tools.unaids.check_area_grouping(area_grouping: str) list
Checks if area grouping is valid and returns a list of area codes
- class bblocks.import_tools.unaids.Aids
Bases:
bblocks.import_tools.common.ImportDataAn object to extract data from UNAIDS.
To use, create an instance of the class. The load indicators using the load_indicators method. This can be done multiple times. To return a dataframe of all available indicators to load, use the available_indicators class attribute. 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, the data will be downloaded each time an indicator is loaded. You can force an update by calling ‘update’, and all indicators will be reloaded into the object. You can get a dataframe by calling ‘get_data’ and passing the indicator name(s) (or None and this will return all indicators) and passing the area grouping(s) (‘all’ by default)
- property available_indicators: pandas.DataFrame
Returns a dataframe of available indicators
- load_data(indicator: str, area_grouping: str = 'all') bblocks.import_tools.common.ImportData
Load an indicator to the object
- indicator (str): The name of the indicator to load. To see a DataFrame of available
indicators, use the available_indicators method.
area_grouping (str): The grouping to use. Choose from [“country”, “region”, “all”].
- Returns:
The same object to allow chaining
- update_data(reload_data: bool)
Update all loaded indicators saved on the disk
When called, it will go through each loaded indicator/area grouping combination and update the data saved on disk.
- Returns:
The same object to allow chaining
- get_data(indicators: str | list | None = None, area_grouping: str = 'all') pandas.DataFrame
Get the data as a Pandas DataFrame
- Parameters:
indicators – By default, all indicators are returned in a single DataFrame. If a list of indicators is passed, only those indicators will be returned. A single indicator can be passed as a string as well.
area_grouping (str) – The area grouping to use. Choose from [“country”, “region”, “all”]. Default is “all”.
- Returns:
A Pandas DataFrame with the requested indicator data