Use statistics.mean(values) to find the arithmetic average of a nonempty collection of numbers. Use median(values) for the middle of the distribution or a weighted mean when observations carry different weights. Show how many values went into the result, especially if some are missing.
Compare a mean and median
from statistics import mean, median
minutes = [6, 7, 8, 9, 70]
assert mean(minutes) == 20
assert median(minutes) == 8
The mean answers how much duration would fall to each record if the total were spread evenly. The median identifies the middle value after sorting. In the example, one long job raises the mean to 20 minutes even though four jobs took under 10. The median describes the middle of this group, while the mean still matters if you need to plan capacity from total work time. Neither calculation tells you why the long job took 70 minutes.
Decide whether the extreme value is valid before excluding it. For a complicated repair, 70 minutes might be the observation that matters most. A duration of 70 minutes for a two-minute test cycle might indicate an incorrect unit or a record left open. Document a data-quality rule with the people who know the source.
Use weights for groups of unequal sizes
If shop A completed two repairs in an average of 10 minutes and shop B completed eight in an average of 20 minutes, the mean across repairs is 18. Multiply each group mean by its job count, add the products, then divide by the sum of job counts. You can express this with statistics.fmean([10, 20], weights=[2, 8]) in Python 3.11 or later. It returns a float. Whenever possible combine original sums and counts rather than means rounded for display.
If your question is about the average shop, treating each shop equally may make sense. That would give 15 minutes here. Call the reported statistic what it is. For percentages, preserve the original count of successes and opportunities. Dividing the combined successes by the combined opportunities is more transparent than weighting several displayed rounded percentages.
Handle empty and missing observations
The statistics functions require valid input. mean([]) raises StatisticsError. If your report legitimately contains a group with no measurements, return an explicit missing marker before calling the function. A zero mean suggests observations existed and averaged to zero. A missing mean says the program had nothing usable to average.
Inspect source conventions. A negative duration might be invalid, a blank could indicate an active job, and zero could be a valid instantaneous measurement within source precision. Track the rows you leave out. If finished repairs get measured more reliably than abandoned repairs, a mean calculated only from measured records may not represent all jobs.
Do not assume NaN behaves like an ordinary number. It can produce confusing or unusable results, especially in functions that sort data. For regular integer or floating point reporting, validate the input and decide whether a nonfinite value triggers rejection. Standardize numeric types before aggregation. Mixing decimal and binary floating-point values can cause errors or change arithmetic expectations.
Report the average with its observation count
A good summary pairs the average with the number of included observations, the number missing when available, and a time range or source label. If pooling subgroups, keep each subgroup’s sum and count in the intermediate output. These are sufficient to reconstruct the combined mean. You cannot generally reconstruct the combined median from subgroup medians alone.
Show enough decimal places for the reader’s decision. If durations were recorded to the nearest minute, six decimal places can suggest that you measured individual repairs more precisely than you did. Keep unrounded sums and counts, then round the reported mean. Check a single observation, two unequal group sizes and an empty group by hand.