metric_forge.ecommerce.polars_ext.Ecommerce_Polars.conversion_rate#
- Ecommerce_Polars.conversion_rate(
- num_conversions_column: str,
- num_visitors_column: str,
Calculate Conversion Rate.
- Parameters:
- num_conversions_column
Total number of conversions for a given time period. Definition is subjective.
- num_visitors_column
Total number of visitors for 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('num_conversions'), ... pl.col('num_visitors'), ... pl.col('*').forge_ecommerce.conversion_rate('num_conversions', 'num_visitors')) shape: (12, 3) ┌─────────────────┬──────────────┬─────────────────┐ │ num_conversions ┆ num_visitors ┆ conversion_rate │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ f64 │ ╞═════════════════╪══════════════╪═════════════════╡ │ 300 ┆ 13154 ┆ 2.280675 │ │ 427 ┆ 14762 ┆ 2.892562 │ │ 367 ┆ 10056 ┆ 3.649562 │ │ 132 ┆ 19948 ┆ 0.66172 │ │ 147 ┆ 13110 ┆ 1.121281 │ │ … ┆ … ┆ … │ │ 392 ┆ 8840 ┆ 4.434389 │ │ 198 ┆ 6028 ┆ 3.284672 │ │ 271 ┆ 12385 ┆ 2.188131 │ │ 459 ┆ 5502 ┆ 8.342421 │ │ 313 ┆ 11910 ┆ 2.628044 │ └─────────────────┴──────────────┴─────────────────┘