wide_to_long_infill#

caf.toolkit.pandas_utils.wide_to_long_infill(df, out_name=None, correct_cols=None, correct_ind=None, infill=None)[source]#

Convert a matrix from wide to long format, infilling missing values.

Parameters:
  • df (DataFrame) – The dataframe, in wide format, to convert to long. The index of df must be the values that are to become index_col_1_name, and the columns of df will be melted to become index_col_2_name.

  • out_name (str | None) – The ‘name’ attribute of the resultant pandas Series. This defaults to ‘val’ if not provided.

  • correct_cols (list | None) – The correct columns of the input matrix.

  • correct_ind (list | None) – The correct index of the input matrix

  • infill (Any) – Value to infill when the matrix is unstacked.

Returns:

A copy of df, in long format, with 3 columns: [index_col_1_name, index_col_2_name, value_col_name]

Return type:

long_df

Raises:

TypeError: – If none of the value_col_name is not numeric and check_totals is True