bhepop2.tools

Utility functions

Module Contents

Functions

add_household_size_attribute(population[, values_map, ...])

Add a size attribute to the given synthetic population.

add_household_type_attribute(population[, person_id, ...])

Add a type attribute to the given synthetic population.

read_filosofi(filepath, year, attributes[, communes])

Fetch income distributions by attribute (age, sex, ...) and commune from Filosofi file

read_filosofi_attributes(filosofi_sheets, year, attributes)

Read distributions from list of attributes and their modalities in filosofi sheets.

read_distributions_from_filosofi(filosofi_sheets, ...)

param filosofi_sheets:

Filosofi excel as DataFrame indexed by sheet

Attributes

filosofi_attributes

bhepop2.tools.add_household_size_attribute(population: pandas.DataFrame, values_map: callable = lambda x: ..., person_id: str = 'person_id', household_id: str = 'household_id', column_name: str = 'size')

Add a size attribute to the given synthetic population.

Even though we add the attribute at a person’s level, its value is related to the household (we add household size).

Parameters:
  • population – synthetic population df

  • values_map – mapping function applied to household count

  • person_id – name of the column containing persons’ ids

  • household_id – name of the column containing households’ ids

  • column_name – name of the added column

Returns:

population with new ‘column_name’ column containing household size

bhepop2.tools.add_household_type_attribute(population, person_id: str = 'person_id', household_id: str = 'household_id', column_name='family_comp')

Add a type attribute to the given synthetic population.

The following attributes are needed on the population:
  • household_size: number of person’s in the household

  • sex: person’s sex

  • age: person’s age

  • couple: boolean indicating if the person is in couple in the household

The household type can take the following values:
  • Single_man

  • Single_wom

  • Couple_without_child

  • Couple_with_child

  • Single_parent

  • complex_hh

Even though we add the attribute at a person’s level, its value is related to the household (we add household type).

Parameters:
  • population – synthetic population df

  • person_id – name of the column containing persons’ ids

  • household_id – name of the column containing households’ ids

  • column_name – name of the added column

Returns:

population with new ‘column_name’ column containing household size

bhepop2.tools.filosofi_attributes
bhepop2.tools.read_filosofi(filepath: str, year: str, attributes: list, communes=None)

Fetch income distributions by attribute (age, sex, …) and commune from Filosofi file

Parameters:
  • filepath – path to Filosofi excel file (DISP_COM)

  • year – Filosofi data year

  • attributes – list of attributes and their modalities, with data required for extraction

  • communes – optional list of communes to filter

Returns:

distributions DataFrame

bhepop2.tools.read_filosofi_attributes(filosofi_sheets, year, attributes: list, communes=None)

Read distributions from list of attributes and their modalities in filosofi sheets.

Parameters:
  • filosofi_sheets – Filosofi excel as DataFrame indexed by sheet

  • year – Filosofi data year

  • attributes – list of attributes and their modalities, with data required for extraction

  • communes – optional list of communes to filter

Returns:

distributions DataFrame

bhepop2.tools.read_distributions_from_filosofi(filosofi_sheets, year: str, sheet: str, col_pattern: str, attribute: str, modality: str, communes=None)
Parameters:
  • filosofi_sheets – Filosofi excel as DataFrame indexed by sheet

  • year – Filosofi data year

  • sheet – sheet name

  • col_pattern – column pattern

  • attribute – attribute name

  • modality – modality name

  • communes – optional list of communes to filter

Returns:

distributions DataFrame