long_product_infill#

pandas_utils.df_handling.long_product_infill(df, index_dict, infill=0, check_totals=False)#

Infill columns with a complete product of one another.

Infills missing values of df in index_dict.keys() columns by generating a new MultiIndex from a product of the values in index_cols.values(). Where a None-like value is given, all unique values are taken from df in that column.

Parameters:
  • df (DataFrame) – The dataframe, in long format, to infill.

  • index_dict (Mapping[str, Collection[Any] | None]) – A dictionary mapping the columns of df to infill, and with what values. Where a None-like value is given, all unique values are taken from df in that column. i.e, df[index_col].unique() will be used.

  • infill (Any) – The value to use to infill any missing cells in the return DataFrame.

  • check_totals (bool) – Whether to check if the totals are almost equal before and after the conversion. Can only be performed on numeric columns.

Returns:

An extended version of ‘df’ with a product of all index_cols.values() in index_cols.keys().

Return type:

infilled_df

Raises:

TypeError: – If none of the non-index columns are numeric and check_totals is True