liveBook · Manning

Normal distribution

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

A probability distribution whose values are symmetrically concentrated around a mean with spread determined by its standard deviation.

A normal distribution produces values centered around a chosen mean, with their spread controlled by standard deviation. Random samples vary, so a generated mean may not exactly match the target. For a normal distribution, about 68% of values fall within one standard deviation of the mean, 95% within two, and 99.7% within three. section 1.15 section 1.5

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

Generate 100,000 normally distributed floating-point values with mean 0 and standard deviation 100, then wrap the NumPy array in a pandas Series. section 1.15

Use pandas descriptive statistics to inspect the resulting shape. Calling describe returns the count, mean, standard deviation, minimum, quartiles, median, and maximum together. A large sample should have a median close to its mean because the distribution is symmetric, though random variation prevents exact equality. section 1.14 section 1.15

count    100000.000000
mean          0.157670
std          99.734467
min        -485.211765
25%         -66.864170
50%           0.172022
75%          67.343870
max         424.177191
dtype: float64

The displayed describe result shows a mean near zero, a median close to the mean, and a standard deviation near the requested 100. section 1.15

Testing sensitivity to an outlier

Replace every occurrence of the minimum value with five times the maximum value using a boolean mask and .loc. Running describe again reveals that the maximum changes dramatically, while the mean and standard deviation shift noticeably. The median changes much less, illustrating why extreme values affect the mean more strongly than the median. section 1.15 section 1.5

Repeated weekday measurements

Generate 28 rounded temperatures from a normal distribution with mean 20 and standard deviation 5. Give the values a repeating Sunday-through-Saturday index, then select the Monday entries and calculate their mean. section 1.18

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

How deep it goes
Explains generation, expected proportions, summary statistics, and outlier effects, but stops short of mathematical derivation.
Examples
Uses a 100,000-value synthetic Series, an extreme-value replacement, and repeated weekday temperature readings.
What it assumes
Assumes familiarity with pandas Series, NumPy arrays, boolean masks, indexing, and basic aggregation methods.
What you can do after
Apply it via NumPy and pandas to generate samples, summarize their distribution, and assess how outliers change statistical measures.
How it connects
Links normal distribution with mean, median, standard deviation, quantiles, descriptive statistics, outliers, and pandas Series.

Also explained in

Compare how 16 books explain normal distribution →

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.