metric_forge.ecommerce.polars_ext.Ecommerce_Polars.cart_abandonment_rate#
- Ecommerce_Polars.cart_abandonment_rate(
- carts_created_column: str,
- completed_purchases_column: str,
Calculate the Cart Abandonment Rate.
- Parameters:
- carts_created_column
Number of online shopping carts created over a given time period.
- completed_purchases_column
Number of completed purchases over a given time period.
- Returns:
- Expr
Examples
>>> import polars as pl ... from metric_forge.ecommerce import * ... data = pl.read_csv('datasets/ecommerce_metrics.csv')
>>> data.select(pl.col('carts_created'), ... pl.col('completed_purchases'), ... pl.col('*').forge_ecommerce.cart_abandonment_rate('carts_created', 'completed_purchases')) shape: (12, 3) ┌───────────────┬─────────────────────┬───────────────────────┐ │ carts_created ┆ completed_purchases ┆ cart_abandonment_rate │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ f64 │ ╞═══════════════╪═════════════════════╪═══════════════════════╡ │ 1969 ┆ 1425 ┆ 27.628238 │ │ 1506 ┆ 1421 ┆ 5.64409 │ │ 1497 ┆ 965 ┆ 35.537742 │ │ 1963 ┆ 1102 ┆ 43.861437 │ │ 1009 ┆ 801 ┆ 20.61447 │ │ … ┆ … ┆ … │ │ 1108 ┆ 601 ┆ 45.758123 │ │ 1975 ┆ 1395 ┆ 29.367089 │ │ 800 ┆ 669 ┆ 16.375 │ │ 2005 ┆ 1215 ┆ 39.401496 │ │ 1704 ┆ 855 ┆ 49.823944 │ └───────────────┴─────────────────────┴───────────────────────┘