brand_sums(all_revenue)

A normalized magnitude version of brand sums.

Source code in wt_ml/dataset/generate_hdf5/__init__.py
64
65
66
67
68
@register
def brand_sums(all_revenue: pd.DataFrame) -> pd.Series:
    """A normalized magnitude version of brand sums."""
    raw_brand_sums = all_revenue.sum().groupby("brand_data").sum()
    return raw_brand_sums / raw_brand_sums.mean()

sales_instability(all_revenue)

Calculate the sales instability metric for each column in the input data.

:param sales: A pandas DataFrame containing all revenue data. :return: A pandas Series or NumPy array containing the sales instability metric for each column. Series index [wholesaler, brand, product]

Source code in wt_ml/dataset/generate_hdf5/__init__.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@register
@compound_return(["instability_mults", "mean_sales"])
def sales_instability(all_revenue: pd.DataFrame) -> Mapping[str, pd.Series]:
    """
    Calculate the sales instability metric for each column in the input data.

    :param sales: A pandas DataFrame containing all revenue data.
    :return: A pandas Series or NumPy array containing the sales instability metric for each column.
    Series index [wholesaler, brand, product]
    """
    sales = all_revenue.swaplevel("brand_data", "product_code", axis=1)
    mean_sales = sales.mean(0)
    loss_mult = mean_sales / mean_sales.mean()
    return {
        "instability_mults": loss_mult,
        "mean_sales": mean_sales,
    }