The statistics module in Python
Mean, median, spread and quantiles without reaching for numpy.
import statistics
runs = [88, 91, 97, 104, 99, 108, 92]
print(statistics.fmean(runs), statistics.median(runs))
print(round(statistics.stdev(runs), 2), round(statistics.pstdev(runs), 2))
print(statistics.quantiles(runs, n=4))
print(statistics.mode([1, 2, 2, 3]), statistics.multimode([1, 1, 2, 2]))
print(round(statistics.correlation(runs, sorted(runs)), 3))
How it works
fmeanis the fast float mean;meanis exact for Fractions.quantilescuts the data into n groups.stdevis the sample deviation,pstdevthe population one.
Keywords and builtins used here
printroundsorted
The run, in numbers
- Lines
- 9
- Characters to type
- 359
- Tokens
- 125
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 71 seconds.
Step 3 of 3 in Configuration & time, step 34 of 41 in Domain tools.