liveBook · Manning

Mean

As explained in The Quick Python Book, Fourth Edition

A mean is a measure of central tendency, calculated as the arithmetic average of values or, for a random variable, as the probability-weighted average of its possible values.

The mean, or average, of a list of numeric observations is their sum divided by their count. section 5.9.3

Average a list in Python

For a list named temperatures, calculate the mean with mean_temp = sum(temperatures) / len(temperatures). section 5.9.3

The values must support arithmetic: missing entries or percentage strings are read as strings, so clean or handle them before calculating an average. section 21.4.1

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Demonstrates the sum-and-count calculation in Python without developing statistical theory.
Examples
Calculates summary statistics for Heathrow monthly high temperatures from 1948 through 2016.
What it assumes
Assumes a list of numeric values and uses sum() and len() rather than teaching list handling from zero.
What you can do after
Apply it via Python's sum() and len() to average a numeric list.
How it connects
Pairs the mean with the median and Python lists.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.