How can we compute a running cumulative sum of revenue per customer across their entire purchase history?
Window.partitionBy().orderBy().rowsBetween(Window.unboundedPreceding, Window.currentRow) accumulates values up to the current row.
Tracking lifetime customer spend, cumulative financial ledgers, and progressive budget utilization.
w = Window.partitionBy("customer_id").orderBy("order_date").rowsBetween(Window.unboundedPreceding, Window.currentRow)
df_cumulative = df.withColumn("running_total", sum("amount").over(w))Practice typing production-grade PySpark code for Cumulative Running Totals with Unbounded Frames.