modelarrayio.utils.misc.cohort_to_long_dataframe

modelarrayio.utils.misc.cohort_to_long_dataframe(cohort_df, scalar_columns=None)[source]

Convert a wide-format cohort dataframe to a long-format dataframe.

Parameters:
  • cohort_df (pandas.DataFrame) – Wide-format cohort dataframe

  • scalar_columns (list) – List of scalar columns to use. If provided, these columns are treated as file-path columns and melted into ‘scalar_name’/’source_file’ rows. All remaining columns (e.g. ‘source_mask_file’) are broadcast to every output row. If not provided, the dataframe is treated as already long-format.

Returns:

long_df – Long-format cohort dataframe with columns ‘scalar_name’, ‘source_file’, and any non-scalar columns from the input.

Return type:

pandas.DataFrame