Section 1 · Lesson 1
Center: mean, median, mode and skew
Summarize a typical value with the mean, median and mode, and use skew to decide which one to report.
Ask “what does a typical order look like?” and you will get at least three different answers. Each measure of center is a different way to squash a whole column into one number, and picking the wrong one can mislead a whole meeting.
Mean
The mean (the “average”) adds everything up and divides by the count:
mean = (x1 + x2 + ... + xn) / n
Think of it as the balance point of the data. Every value pulls on it, so a few very large values drag it upward. One $1,121 order counts as much as twenty-five $45 orders.
Median
Sort the values and take the middle one (with an even count, average the two middle values). Half the data is below the median and half is above. Because it only cares about position, the median barely moves when you add a huge outlier. Statisticians call it robust.
Mode
The mode is the most frequent value. It is most useful for categories (most common device, most common channel) or small whole numbers (most common number of items per order). For continuous amounts like $47.89 it is rarely meaningful, and a column can have several modes.
Skew: the shape tells you which center to trust
- Right-skewed (positive skew): a long tail of large values. The mean is pulled above the median. This is the normal shape of money data: order values, revenue per user, cost per click, time to purchase.
- Left-skewed (negative skew): a long tail of small values; the mean sits below the median (for example, satisfaction scores bunched near 5 out of 5).
- Symmetric: mean and median are close.
Skewness is roughly the average of the cubed z-scores, ((x - mean) / sd) ** 3, with a
small-sample correction. Cubing keeps the sign, so a long right tail gives a positive number.
Rough guide: under 0.5 in absolute value is fairly symmetric, above 1 is strongly skewed.
In Python
import pandas as pd
orders = pd.read_csv("orders.csv")
# .loc[row_filter, column] keeps matching rows and returns one column
amount = orders.loc[orders["status"] == "completed", "amount"]
amount.mean() # arithmetic mean
amount.median() # middle value
amount.mode() # a Series of the most common value(s)
amount.skew() # sample skewness: > 0 means a long right tail
amount.describe() # count, mean, std, min, quartiles and max in one call
On the course data the mean completed order is about $76 while the median is about $47. The mean is roughly 60% higher than the “typical” order because a small number of large orders stretch the right tail. In the tasks you will also see that most orders fall below the average, which surprises people the first time.
In the real world
- To describe the typical customer, report the median: median order value, median time on page, median days to convert.
- To forecast totals, use the mean: total revenue = mean revenue per user × number of users. That is why A/B tests on revenue compare means, not medians.
- Always look at both. A big gap between mean and median is a cue to check the tail: bulk buyers, bots, or a data error (an extra zero) can move the mean on their own.
Practice
Write your answer, press Run to see results and Check answer to grade it. Shortcuts: Ctrl/⌘ + Enter run, Shift + Enter check.
Mean vs median order value
DoneLoad orders.csv and keep only the rows whose status is "completed". For the amount column, create:
mean_amount: the mean, rounded to 2 decimals withround()median_amount: the median, rounded to 2 decimals
Print both. Which one is bigger, and what does that tell you?
Need a hint?
- Filter with a boolean mask:
orders[orders["status"] == "completed"]. .mean()and.median()work on a single column (a Series). Wrap each inround(..., 2).
Practice tasks, quizzes and the certificate are part of the course. The first lesson is free to try.
import pandas as pd
orders = pd.read_csv("orders.csv")
completed = orders # TODO: keep only completed orders
mean_amount = None
median_amount = None
print(mean_amount, median_amount)
Files in the working directory
ab_test.csv (4,000 rows)daily_stats.csv (1,561 rows)orders.csv (900 rows)campaigns.csv (40 rows)Which way does it skew?
DoneUsing the amount of completed orders again, create:
skewness: the sample skewness from pandas'.skew(), rounded to 2 decimalsskew_direction: the string"right"if the data is right-skewed (positive skewness,
long tail of big values) or "left" if it is left-skewed (negative skewness)
pct_below_mean: the fraction of completed orders whose amount is below the mean,
rounded to 3 decimals (for example 0.5 would mean half)
Need a hint?
amount.skew()returns pandas' bias-adjusted sample skewness.amount < amount.mean()gives a True/False Series;.mean()of it is the share of True values.
Practice tasks, quizzes and the certificate are part of the course. The first lesson is free to try.
import pandas as pd
orders = pd.read_csv("orders.csv")
amount = orders.loc[orders["status"] == "completed", "amount"]
skewness = 0
skew_direction = "?"
pct_below_mean = 0
print(skewness, skew_direction, pct_below_mean)
Files in the working directory
ab_test.csv (4,000 rows)daily_stats.csv (1,561 rows)orders.csv (900 rows)campaigns.csv (40 rows)The most common device
DoneThe mode also works for categories. Load ab_test.csv and create:
top_device: the most common value of thedevicecolumn (a string), using.mode()top_device_share: the fraction of all users on that device, rounded to 3 decimals
.mode() returns a Series (there can be ties), so take the first value with .iloc[0].
Need a hint?
ab["device"].mode().iloc[0]gives the single most common value.(ab["device"] == top_device).mean()is the share of rows on that device.ab["device"].value_counts(normalize=True)shows all shares at once.
Practice tasks, quizzes and the certificate are part of the course. The first lesson is free to try.
import pandas as pd
ab = pd.read_csv("ab_test.csv")
top_device = ab["device"].mode() # this is still a Series
top_device_share = 0
print(top_device, top_device_share)
Files in the working directory
ab_test.csv (4,000 rows)daily_stats.csv (1,561 rows)orders.csv (900 rows)campaigns.csv (40 rows)