How can we calculate a 7-day moving average of daily active users to smooth out weekend fluctuations?
rowsBetween(-6, Window.currentRow) defines a rolling sliding window of 7 discrete consecutive observations.
Algorithmic trading signals, smoothing noisy sensor telemetry, and weekly trend analysis.
w = Window.partitionBy("metric_name").orderBy("date").rowsBetween(-6, Window.currentRow)
df_moving_avg = df.withColumn("7_day_avg", avg("daily_value").over(w))Practice typing production-grade PySpark code for Moving Average with Sliding Window Frames.