Catch an average of averages
Task
Calculate the average order value in each region, average those four averages, and compare the result with the true average over all orders. Then work out why they differ.
Steps
- Join valid orders to customers and products and calculate each order's net value.
- Record each region's order count and mean in
lab/avg/regions.csvwith headerregion,orders,mean, means to two decimal places. - Record in
lab/avg/compare.txtthe linesmean of region means: Nandtrue mean: N, to two decimal places.
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 {print $1": "$2" orders, mean "$3}' lab/avg/regions.csv
grep -E '^(mean of region means|true mean): ' lab/avg/compare.txt
The mean of the four region means is 179.49; the true mean over all 1997 orders is 177.58. West has the fewest orders but the highest mean, and averaging the averages gives its 460 orders the same weight as South's 519. The fix is to divide total value by total orders, never to average the averages.
This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.