metric_forge.ecommerce.polars_ext.Ecommerce_Polars.customer_acquisition_cost#
- Ecommerce_Polars.customer_acquisition_cost(
- cost_column: str,
- customers_column: str,
Calculate Customer Acquisition Cost (CAC).
- Parameters:
- cost_column
Total Customer Aquisition Costs
- customers_column
Number of New Customers
- Returns:
- Expr
Examples
>>> import polars as pl ... from metric_forge.ecommerce import * ... data = pl.read_csv('datasets/ecommerce_metrics.csv')
>>> data.select(pl.col('cost_of_acquisition'), ... pl.col('new_customers'), ... pl.col('*').forge_ecommerce.customer_acquisition_cost('cost_of_acquisition', 'new_customers')) shape: (12, 3) ┌─────────────────────┬───────────────┬───────────────────────────┐ │ cost_of_acquisition ┆ new_customers ┆ customer_acquisition_cost │ │ --- ┆ --- ┆ --- │ │ f64 ┆ i64 ┆ f64 │ ╞═════════════════════╪═══════════════╪═══════════════════════════╡ │ 22958.350559 ┆ 406 ┆ 56.547661 │ │ 18736.874206 ┆ 234 ┆ 80.072112 │ │ 28355.586842 ┆ 120 ┆ 236.296557 │ │ 14184.81582 ┆ 428 ┆ 33.142093 │ │ 18764.339456 ┆ 266 ┆ 70.54263 │ │ … ┆ … ┆ … │ │ 33555.278842 ┆ 188 ┆ 178.485526 │ │ 15990.213465 ┆ 415 ┆ 38.530635 │ │ 25427.033152 ┆ 113 ┆ 225.017992 │ │ 27772.437066 ┆ 341 ┆ 81.444097 │ │ 11393.512382 ┆ 364 ┆ 31.300858 │ └─────────────────────┴───────────────┴───────────────────────────┘