← Data analysis with Python

Mode, minimum, maximum and range

The most common value, and how far the values stretch.

Start this lesson

The mode is the value that appears most often. It is the only "typical value" that works for categories too: the most common shoe size, or the most popular menu item. The minimum and maximum are the smallest and largest values, and the range is max minus min. The range is a quick first look at spread: are the values packed together, or stretched far apart?

temps = [21, 24, 19, 24, 28, 24, 22]
counts = {}
for t in temps:
    counts[t] = counts.get(t, 0) + 1
mode = max(counts, key=counts.get)
print("mode:", mode)
print("range:", max(temps) - min(temps))

The dictionary counts how often each value appears; the key with the biggest count is the mode (24). The range is 28 - 19 = 9 degrees.

A list can have two or more modes when values tie. The range depends only on the two most extreme values, so a single odd reading can make it huge.