What is a percentile, and how is it different from a quartile?
A percentile is the value below which a given percentage of the data falls. Quartiles are just three special percentiles: Q1 is the 25th, Q2 the 50th (the median) and Q3 the 75th.
Explain it simply
Think of a college exam result. If your marks are at the 90th percentile, 90% of students scored below you. A percentile tells you where a value stands in the crowd, not how big it is.
Quartiles cut the sorted data into four equal-sized groups. They are percentiles with fixed positions: 25th, 50th and 75th.
Example
Ten students scored 35, 42, 48, 55, 60, 62, 70, 75, 81, 95.
import numpy as np
marks = [35, 42, 48, 55, 60, 62, 70, 75, 81, 95]
print(np.percentile(marks, [25, 50, 75])) # [49.75 61. 73.75]The median is 61 (halfway between 60 and 62). Q1 = 49.75 and Q3 = 73.75. NumPy sits between two neighbouring values when the position is not a whole number, so Q1 lies between 48 and 55. The IQR is Q3 - Q1 = 24.
What to say in the interview
"A percentile is a rank-based position: the pth percentile has p% of observations at or below it. Quartiles are the 25th, 50th and 75th percentiles. I use them because they are robust to outliers, unlike the mean, and the gap between Q1 and Q3, the IQR, describes the spread of the middle half."
Common mistakes
- Confusing "90th percentile" with "scored 90 marks".
- Forgetting that different tools use slightly different interpolation, so Q1 can differ by a small amount.