bblocks.import_tools.unaids

Tools to retrieve data from UNAIDS

Attributes

URL

AREA_CODES

AVAILABLE_INDICATORS

Classes

Aids

An object to extract data from UNAIDS.

Functions

get_response(→ dict)

returns a json response from UNAIDS

parse_data_table(→ pandas.DataFrame)

parses data table in json response and returns a formatted dataframe

parse_global_data(→ pandas.DataFrame)

parses global data in json response and returns a formatted dataframe

clean_data(→ pandas.DataFrame)

cleans dataframe and returns a formatted dataframe

get_category(→ str)

returns the category for an indicator

check_response(→ None)

checks if response has data

get_dimensions(→ list)

returns the dimensions for an indicator

get_years(→ list)

returns the years for an indicator

response_params(group, indicator)

Returns a list of parameters to be used in the response

response_to_df(→ pandas.DataFrame)

Convert response to dataframe

extract_data(indicator, grouping)

pipeline to extract data

check_if_not_downloaded(→ bool)

Checks if data is already downloaded for an indicator and area grouping

check_area_grouping(→ list)

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.ImportData

An 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