TWIL - Calculate days between sales using polars

The solution I settled with in the end was: df.group_by( "customer", "product_type" ).agg( pl.col.date.diff().dt.total_days().alias("DiffDays"), ).with_columns( pl.col.DiffDays.list.mean().round(1).alias("Avg_Days_Between_Deals") ).drop("DiffDays") I am currently doing quite a bit of revenue data analysis at my job. The other day my manager came up to me and told me that he wanted to add additional KPIs to the analysis. The given dataset looks like that: date [str] product_type [str] customer [str] revenue [float64] 2024-05-10 Product A Example Corp 3400....

August 17, 2025 · 2 min · 361 words · Max Häming