Data Handling using Pandas - II
Mean, median, mode, quartiles and spread
Compute and interpret the central value and spread of marks.
Measures of centre:
- mean(): the average. In pandas 2, add numeric_only=True when the DataFrame has a text column, like Name.
- median(): the middle value when the data are sorted.
- mode(): the most frequent value. If marks are 18, 21, 21 and 25, the mode is 21.
Quartiles divide sorted data into four equal parts: quantile(q=.25) gives the first quartile, quantile() (q=.5 by default) the median, and quantile(q=.75) the third quartile.
Measures of spread:
- var(): the variance, the average squared distance from the mean. (Pandas divides by n − 1, not n.)
- std(): the standard deviation, the square root of the variance.
describe() shows several of these together for each numeric column: count, mean, std, min, the three quartiles (25%, 50%, 75%) and max. Centre and spread.
Centre and spread.
Practise this lesson
Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.
No account, no email address. Opens the real product.