Distribution Metrics
ACV (All Commodity Volume) metric.
ACV measures total sales across all products in a set of stores.
Acv
Calculates ACV (All Commodity Volume): summed spend divided by acv_scale_factor.
NaN values in the spend column are excluded from the sum. table (ibis) and df
(pandas) have an acv column plus any group_col columns as ordinary columns
(RangeIndex), one row per group in no particular order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | Table
|
Transaction data containing at least a unit_spend column. |
required |
group_col
|
str | list[str] | None
|
Optional column(s) to group the ACV calculation by (e.g., store_id). Defaults to None for total ACV. |
None
|
acv_scale_factor
|
float
|
Divisor; the default 1,000,000 gives millions of the spend currency. |
1000000
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If df is not a pandas DataFrame or an Ibis Table. |
ValueError
|
If required columns are missing from the data or if acv_scale_factor is not positive. |
Source code in openretailscience/experimental/metrics/distribution/acv.py
df
cached
property
Returns the materialized pandas DataFrame of ACV results.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Single |
__init__(df, *, group_col=None, acv_scale_factor=1000000)
Initializes the ACV calculation.
Source code in openretailscience/experimental/metrics/distribution/acv.py
% of Stores (Numeric Distribution) metric.
% of Stores measures the share of total stores in the dataset that sell a given product. Every store counts equally regardless of its sales volume.
PctOfStores
Calculates the unweighted percentage of stores selling each product.
table (ibis) and df (pandas) have one row per product (and group), in no particular
order, with the product and group columns as ordinary columns (RangeIndex), stores
(column.agg.store_id) and stores_pct (column.agg.store_id + column.suffix.percent).
stores_pct is on a 0-100 scale (distribution points), not a fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame | Table
|
Transaction-level data containing at least store_id and product_id columns. |
required |
product_col
|
str | list[str] | None
|
Column(s) defining product granularity.
Defaults to |
None
|
group_col
|
str | list[str] | None
|
Additional grouping dimensions
(e.g., |
None
|
within_group
|
bool
|
Controls the denominator when |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If df is not a pandas DataFrame or an Ibis Table. |
ValueError
|
If required columns are missing from the data, or if product_col appears in group_col. |
Source code in openretailscience/experimental/metrics/distribution/pct_of_stores.py
df
cached
property
Returns the materialized pandas DataFrame of % of Stores results.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with % of stores values. |
__init__(df, *, product_col=None, group_col=None, within_group=False)
Initializes the % of Stores calculation.