metric_forge.ecommerce.polars_ext.Ecommerce_Polars.average_order_value#
- Ecommerce_Polars.average_order_value(
- total_revenue_column: str,
- number_of_orders_column: str,
Calculate the Average Order Value (AOV).
- Parameters:
- total_revenue_column
Total Revenue
- number_of_orders_column
Number of Orders
- Returns:
- Expr
Examples
>>> import polars as pl ... from metric_forge.ecommerce import * ... data = pl.read_csv('datasets/ecommerce_metrics.csv')
>>> data.select(pl.col('total_revenue'), ... pl.col('new_customers'), ... pl.col('*').forge_ecommerce.average_order_value('total_revenue', 'number_of_orders')) shape: (12, 3) ┌───────────────┬───────────────┬─────────────────────┐ │ total_revenue ┆ new_customers ┆ average_order_value │ │ --- ┆ --- ┆ --- │ │ f64 ┆ i64 ┆ f64 │ ╞═══════════════╪═══════════════╪═════════════════════╡ │ 87454.011885 ┆ 406 ┆ 88.248246 │ │ 145071.430641 ┆ 234 ┆ 158.895324 │ │ 123199.394181 ┆ 120 ┆ 94.405666 │ │ 109865.84842 ┆ 428 ┆ 124.142202 │ │ 65601.864044 ┆ 266 ┆ 94.937575 │ │ … ┆ … ┆ … │ │ 136617.614577 ┆ 188 ┆ 206.996386 │ │ 110111.501174 ┆ 415 ┆ 114.819084 │ │ 120807.25778 ┆ 113 ┆ 148.594413 │ │ 52058.44943 ┆ 341 ┆ 99.920248 │ │ 146990.985216 ┆ 364 ┆ 195.466736 │ └───────────────┴───────────────┴─────────────────────┘