Understanding and Calculating Mean, Median, and Mode
In statistics, mean, median, and mode are fundamental concepts that help us understand and describe data. They are measures of central tendency, each providing a unique perspective on where the 'middle' of a data set lies. Let's delve into each of these concepts, their formulas, and how to calculate them.
Mean: The Average of Data
The mean is the most commonly used measure of central tendency. It's calculated by summing all the data points and then dividing by the number of data points. In other words, it's the average of the data.
Formula: Mean (μ) = (Σx) / N

- Σx: The sum of all data points
- N: The total number of data points
Example
Consider the following data set: 4, 9, 5, 8, 7. To find the mean:
- Sum the data points: 4 + 9 + 5 + 8 + 7 = 33
- Count the data points: N = 5
- Divide the sum by the count: Mean = 33 / 5 = 6.6
Median: The Middle Value
The median is the middle value when a data set is ordered from least to greatest. If there's an even number of data points, the median is the average of the two middle numbers.
Formula: Median = (x_(n/2) + x_(n/2 + 1)) / 2

- x_(n/2): The middle number(s) when data is ordered
- n: The total number of data points
Example
Using the same data set as before: 4, 5, 7, 8, 9. To find the median:
- Order the data: 4, 5, 7, 8, 9
- Identify the middle value: The third value, 7
Mode: The Most Frequent Value
The mode is the value that appears most frequently in a data set. A data set can have one mode (unimodal), two modes (bimodal), multiple modes (multimodal), or no mode at all.
Formula: Mode = The value(s) with the highest frequency
Example
Consider the following data set: 4, 9, 5, 8, 7, 7, 9. To find the mode:
- Count the frequency of each value: 4 (1), 5 (1), 7 (2), 8 (1), 9 (2)
- Identify the value(s) with the highest frequency: 7 and 9
When to Use Each Measure
Choosing the right measure of central tendency depends on the data set and the question you're trying to answer.
- Mean: Use when data is symmetric and has no outliers. It's the most commonly used measure.
- Median: Use when data is skewed or has outliers. It's less affected by extreme values.
- Mode: Use when you want to identify the most common value. It's useful for categorical data or when data is unimodal.
Calculating Mean, Median, and Mode in Python
Python's statistics module and pandas library make it easy to calculate mean, median, and mode.
| Measure | Python Function |
|---|---|
| Mean | import statistics mean = statistics.mean(data) or import pandas as pd mean = pd.Series(data).mean() |
| Median | import statistics median = statistics.median(data) or import pandas as pd median = pd.Series(data).median() |
| Mode | from scipy import stats mode = stats.mode(data)[0][0] |