long_product_infill#
- caf.toolkit.pandas_utils.df_handling.long_product_infill(data: DataFrame, infill: Any = 0, check_totals: bool = False, index_dict: dict[Hashable, list] | None = None) DataFrame [source]#
- caf.toolkit.pandas_utils.df_handling.long_product_infill(data: Series, infill: Any = 0, check_totals: bool = False, index_dict: dict[Hashable, list] | None = None) Series
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:
data – The data, as a pandas Series or DataFrame, to infill.
infill – The value to use to infill any missing cells in the return DataFrame.
check_totals – Whether to check if the totals are equal before and after infill. If ‘infill’ is set to anything other than zero, this must be set to False or an error will be raised.
index_dict – Define expected values in indices. This dict will form the index of the infilled Series. The keys of this dict must match the names of the index levels in your input Series, and all values in the input Series must be included in this dict. If this is left as None, the infilled index will simply be the product of all values in the current index.
- 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