Separate a month's rise from the length of the month

short · 35 min · Objective 3.2

Task

Count orders per month, work out the month-over-month change from February to March, then recalculate it per day, and smooth the series with a three-month moving average.

Steps

  1. Count orders per month in data/orders.csv and save them to lab/trend/monthly.csv with header month,orders.
  2. Calculate the February-to-March change as a percentage of February, and again using orders per day (February has 28 days, March 31). Record them in lab/trend/change.txt as per month: N and per day: N, to one decimal place.
  3. Add a three-month moving average for each month from March onwards to lab/trend/smoothed.csv with header month,orders,moving_average, averages to one decimal place.

Verify

These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.

awk -F, 'NR>1 {n++; s+=$2} END {print n" months, "s" orders"}' lab/trend/monthly.csv
grep -E '^per (month|day): ' lab/trend/change.txt
tail -1 lab/trend/smoothed.csv

Twelve months and 2000 orders. February to March rises 19.7% per month but only 8.1% per day: more than half the headline increase is three extra days. December's three-month moving average is 173.0. These orders were generated at a steady random rate, so there is no real trend here at all -- only calendar and noise.

This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.