Paul's Python CoursePPC

Mean, median, mode and spread

Not met yet

The mean shares the total out equally; the median is the middle reading once they're sorted; the mode is the most common value. With a few very large readings the mean is dragged up and the median hardly moves, so for skewed things like daily rain the median is the typical day. Spread matters as much as the centre: two places with the same mean can have very different years. The variance is the average squared distance from the mean and the standard deviation is its square root; pandas' std() divides by one less than the count, NumPy's np.std by the count itself unless given ddof=1.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks the median is halfway between the smallest and largest readings, rather than the middle reading once they are sorted.
  • Thinks the median is the most common value, which is the mode.
  • Thinks the mean is the typical reading even when a few very large readings pull it far above most of the others.
  • Thinks one extreme reading moves the median as much as it moves the mean. The median depends only on the order of the readings, so it barely moves.
  • Thinks NumPy's std and pandas' std give the same answer. NumPy divides by the number of readings, pandas by one less.
  • Thinks two sets of readings with the same mean are alike, when their spread can be very different.

Where it comes up