biogeme.database.panel module

PanelStructure: Handles organization and indexing of panel data, where observations are grouped by individuals.

Michel Bierlaire Wed Mar 26 19:33:13 2025

class biogeme.database.panel.PanelDatabase(database, panel_column)[source]

Bases: object

Encapsulates a pandas DataFrame for Biogeme, in panel format,

Parameters:
  • database (Database)

  • panel_column (str)

flatten_database(missing_data)[source]

Flatten a long-format dataframe into a wide-format dataframe where each row represents one individual and columns represent multiple observations.

Parameters:

missing_data (float) – value to use if data is missing.

Return type:

tuple[DataFrame, int]

Returns:

a tuple containing two things: - A wide-format DataFrame where each row corresponds to one individual. For each variable column in the original DataFrame (excluding grouping_column), the output contains multiple columns named columnname_XX, where XX is the zero-padded observation index (starting at 01). Additionally, for each observation index, a relevant_XX column indicates whether the observation is relevant (1) or padded with a missing value (0).

  • The size of the largest group.

biogeme.database.panel.observation_suffix(index)[source]

Return a zero-padded suffix for observation index (1-based).

Return type:

str

Parameters:

index (int)