liveBook · Manning

Mean

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

The arithmetic average of a collection of numerical values, also serving as the central-location parameter of a normal distribution.

The mean is the arithmetic average: add the values and divide by their count. For a numeric pandas Series, `s.mean()` returns this central-value summary; equivalently, it matches `s.sum() / s.count()`, so non-NaN values supply the count. Even an integer Series produces a float mean. section 1.5 section 1.3

Use a mean to make a large collection comparable through one number: average height, income, test score, temperature, trip distance, or salary. It is most useful as a starting point for a question, rather than as a complete description of a distribution. section 1.5 section 3.1

Summarize a Series, then inspect the context

`s.describe()` gathers count, mean, standard deviation, minimum, quartiles, median, and maximum in one returned Series. For 100,000 values drawn from a normal distribution with mean 0 and standard deviation 100, a sampled mean can be near—but not exactly—0. The median should also be close because the normal distribution places half its values below the mean and half above it. section 1.15 section 1.14

g = np.random.default_rng(0)
s = Series(g.normal(0, 100, 100_000))   #1

Create a reproducible Series of normally distributed values, then use it to compare its requested distribution mean with the observed sample mean. section 1.15

A mean is sensitive to extreme values. Replacing a single minimum with a value five times the maximum changes the mean and standard deviation, while the median changes far less. Compare mean with median, minimum, maximum, and standard deviation before treating it as the dataset’s “middle.” section 1.14 section 1.5

Scale scores to a target average

To shift every test score so the final average is 80, compute the scalar adjustment `80 - s.mean()` and add it to the Series: `s + (80 - s.mean())`. This moves from a Series to a scalar mean and back to a new Series through broadcasting; the result has floating-point values. section 1.6 section 1.7

Means become more informative when calculated on a deliberately selected subset:

  • Select repeated Monday index values from four weeks of temperatures, then find their mean temperature. section 1.18
  • Compare the mean of values above `s.mean()` with the mean of values below it, or examine values beyond three standard deviations. section 1.17
  • Slice a yearly score Series into two periods, calculate each period’s mean, and compare the averages. section 1.3
  • Filter taxi rides by below-average distance and above-average cost to identify unusual records. section 3.1

The same operation supports grouped and indexed analysis: calculate average SAT scores for selected states and years, average athlete age or height after multi-index selection, or average tourism values across years before ranking countries. The mean summarizes the rows retained by each selection. section 4.5 section 6.9

Means also work on derived numeric Series. Count vowels in each word with `apply`, then call `mean()` on those counts to obtain the mean vowels per word. This pattern separates constructing a measurement from summarizing it. section 9.2

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines arithmetic calculation, demonstrates pandas methods and broadcasting, and warns about outlier sensitivity without pursuing deeper statistical theory.
Examples
Uses test scores, normally distributed values, temperatures, taxi rides, athlete data, tourism data, and vowel counts.
What it assumes
Starts from numeric pandas Series and extends their use with indexes, slices, boolean masks, and scalar arithmetic.
What you can do after
Apply it via pandas `Series.mean()` to summarize, compare, filter, and rescale numeric data.
How it connects
Connects mean to median, standard deviation, quantiles, descriptive statistics, indexes, slicing, masking, and broadcasting.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.