Many series repeat on a fixed cycle: traffic by hour of day, sales by day of week, demand by month. To see that pattern you average every value that shares the same position in the cycle — all the Mondays together, all the Tuesdays together, and so on.
Task: write seasonal_average(series, period) returning period averages, each rounded to 4 decimal places.
p of the output averages series[p], series[p + period], series[p + 2·period], …period entries, whatever the length of the series.Python's extended slice does the grouping in one expression: series[p::period] takes every period-th element starting at p.
What you get back is the seasonal profile, and it's useful in two directions. Read forwards, it's the shape of the cycle — Saturdays are busy, Tuesdays are dead. Read backwards, it's something to subtract: take each value minus its position's average and the cycle disappears, leaving the trend and the genuinely unusual days visible. That subtraction is seasonal adjustment, and it's why this simple average is the first step of nearly every seasonal decomposition.