API Reference

Main Functions

The lost_years package provides three main functions for calculating expected years of life lost:

lost_years_ssa

lost_years.lost_years_ssa(df, cols=None)

Appends Life expectancycolumn from SSA data to the input DataFrame based on age, sex and year in the specific cols mapping

Parameters:
  • df (DataFrame) – Pandas DataFrame containing the input data.

  • cols (dict[str, str] | None) – Column mapping for age, sex, and year in DataFrame. If None, uses default mapping: {‘age’: ‘age’, ‘sex’: ‘sex’, ‘year’: ‘year’}

Returns:

‘ssa_age’, ‘ssa_year’, ‘ssa_life_expectancy’

Return type:

Pandas DataFrame with life expectancy columns

lost_years_hld

lost_years.lost_years_hld(df, cols=None)

Appends Life expectancy column from HLD data to the input DataFrame based on country, age, sex and year in the specific cols mapping.

Parameters:
  • df (DataFrame) – Pandas DataFrame containing the input data.

  • cols (dict[str, str] | None) – Column mapping for country, age, sex, and year in DataFrame. None for default mapping: {‘country’: ‘country’, ‘age’: ‘age’, ‘sex’: ‘sex’, ‘year’: ‘year’}.

Returns:

‘hld_country’, ‘hld_age’, ‘hld_sex’, ‘hld_year’, ‘hld_life_expectancy’.

Return type:

Pandas DataFrame with HLD data columns

lost_years_who

lost_years.lost_years_who(df, cols=None)

Appends Life expectancy column from WHO data to the input DataFrame based on country, age, sex and year in the specific cols mapping.

Parameters:
  • df (DataFrame) – Pandas DataFrame containing the input data.

  • cols (dict[str, str] | None) – Column mapping for country, age, sex, and year in DataFrame. None for default mapping: {‘country’: ‘country’, ‘age’: ‘age’, ‘sex’: ‘sex’, ‘year’: ‘year’}.

Returns:

‘who_country’, ‘who_age’, ‘who_sex’, ‘who_year’, …

Return type:

Pandas DataFrame with WHO data columns

Module Details

SSA Module

class lost_years.ssa.LostYearsSSAData[source]
lost_years.ssa.main(argv=['-M', 'html', 'source', 'build'])[source]
Return type:

int

HLD Module

HLD (Human Life-Table Database) module for lost_years package.

Provides access to historical life table data from lifetable.de covering 142 countries from 1751-2023.

class lost_years.hld.LostYearsHLDData[source]

HLD data handler for life table information.

lost_years.hld.main(argv=['-M', 'html', 'source', 'build'])[source]

Main CLI function.

Return type:

int

WHO Module

class lost_years.who.LostYearsWHOData[source]
classmethod convert_agegroup(ag)[source]
lost_years.who.main(argv=['-M', 'html', 'source', 'build'])[source]
Return type:

int

Utilities

lost_years.utils.isstring(s)[source]
Return type:

bool

lost_years.utils.column_exists(df, col)[source]

Check the column name exists in the DataFrame.

Parameters:
Returns:

True if exists, False if not exists.

Return type:

bool

lost_years.utils.fixup_columns(cols)[source]

Replace index location column to name with col prefix

Parameters:

cols (list[Any]) – List of original columns

Return type:

list[str]

Returns:

List of column names

lost_years.utils.closest(lst, c)[source]

Find closest value in list or array.

Parameters:
  • lst (list[float] | ndarray[tuple[Any, ...], dtype[floating[Any]]]) – List of floats or numpy array

  • c (float) – Target value to find closest match for

Return type:

float

Returns:

Closest value in the list/array

lost_years.utils.download_file(url, local_path=None)[source]
Return type:

None