Descriptive Statistics
Descriptive statistics summarise a distribution's centre, spread and shape, so we can understand data without reading every row.
s = df["alcohol"]
print("Mean :", s.mean())
print("Median :", s.median())
print("Mode :", s.mode().iloc[0])
print("Std :", s.std())
q1, q3 = s.quantile([0.25, 0.75])
print("IQR :", q3 - q1)
print("Skewness :", s.skew())
print("Kurtosis :", s.kurt()) # excess kurtosis (normal = 0)
1. Mean
The average: sum of all values divided by the number of observations.
- Best for: roughly symmetric data without extreme values, e.g. comparing average income across departments.
- Not suitable: skewed data or data with outliers - extreme values pull the mean away from the typical value.
- Example: average monthly sales of a store over a year.
Numeric illustration: salaries 30, 32, 33, 35, 400 (thousand). Mean = 106 - nobody earns near 106.
2. Median
The middle value after sorting. Half the values are below it, half above. It is robust to outliers.
- Best for: skewed data or data with outliers.
- Not suitable: when you need every value's magnitude to count (it ignores how far the other values are).
- Example: household incomes - a few very rich households distort the mean, so the median is the better "typical" value.
For the salaries above the median is 33 - a much fairer summary.
3. Mode
The most frequent value or category.
- Best for: categorical or discrete data, e.g. the best-selling product in a campaign.
- Not suitable: continuous measurements such as height or weight, where exact repeats are rare.
- Example: which product was sold the most.
A dataset may have no mode, one mode, or several (bimodal, multimodal).
4. Standard deviation (std)
The typical distance of values from the mean. Low std = values close to the mean; high std = widely spread.
- Best for: measuring variability, e.g. day-to-day variation in website traffic.
- Not suitable: heavily skewed data or data with outliers, since it is sensitive to them.
- Example: an e-commerce site with big spikes on sale days has a high std of daily visits.
For roughly normal data: about 68% of values lie within 1 std of the mean, 95% within 2 std, 99.7% within 3 std.
5. Interquartile range (IQR)
IQR = Q3 - Q1, the spread of the middle 50% of the data. Robust to outliers.
- Best for: describing spread when outliers are present and detecting outliers (the 1.5 x IQR rule).
- Not suitable: when you need the spread of the whole data including extremes (use range or std then).
- Example: the range of scores of the middle half of a class, ignoring a few unusually high or low scores.
Outlier fences: lower = Q1 - 1.5 x IQR, upper = Q3 + 1.5 x IQR.
6. Skewness
Measures asymmetry: does the distribution lean right (positive) or left (negative)?
- Best for: deciding whether a transformation is needed before algorithms sensitive to skew (linear regression).
- Not suitable: for data already symmetric - skewness is near zero and adds little.
- Example: monthly sales of a product with holiday peaks are right-skewed; apply a log transform to stabilise variance.
| Skewness | Interpretation |
|---|---|
| -0.5 to +0.5 | approximately symmetric |
| 0.5 to 1 (or -1 to -0.5) | moderately skewed |
| beyond +/-1 | highly skewed |
7. Kurtosis
Measures tailedness: heavy tails (many extreme values) versus light tails, compared with a normal distribution.
- Best for: finding datasets with more outliers than expected. High kurtosis warns about extreme values that can hurt some models.
- Not suitable: near-normal data where tails are not of interest.
- Example: daily stock returns. High kurtosis signals possible extreme loss days, so use robust statistics or adjust risk models.
pandas reports excess kurtosis (normal = 0). Positive = heavier tails than normal; negative = lighter tails.
Comparison of mean and median: a quick diagnostic
| Relationship | Likely shape |
|---|---|
| mean = median | symmetric |
| mean greater than median | right-skewed |
| mean less than median | left-skewed |
Group summaries
df.groupby("quality")["alcohol"].agg(["count", "mean", "median", "std", "min", "max"])