Data Science Percentiles
Choose and record the percentile convention rather than relying on a hidden default.
How it works
A percentile locates a point in an ordered distribution. With a small finite sample, different interpolation conventions can give different answers between observations. NumPy exposes this choice through method. Percentiles are useful for describing a tail, but a ninety-fifth percentile from a tiny sample is a fragile summary rather than a reliable service-level promise.
Run the code
Try in playground opens the correct numpy editor and preloads the complete source. Choose Run to execute; loading does not execute it. The isolated browser runtime does not read personal PC files.
Local review: Python 3.12.14, NumPy 2.5.4, Pandas 3.0.6 and SciPy 1.18.0. Browser review: Pyodide 0.27.7, Python 3.12.7, NumPy 2.0.2, Pandas 2.2.3 and SciPy 1.14.1 in their respective editors. Save the download as percentiles.py and run python percentiles.py in your separate environment. Apache and MySQL are not needed. Environment setup.
Example
import numpy as np
wait = np.array([2., 4., 8., 10.])
q = np.percentile(wait, [25, 50, 75], method="linear")
assert np.allclose(q, [3.5, 6., 8.5], rtol=0, atol=1e-12)
print("Linear quartiles: 3.5, 6.0, 8.5 minutes")
Expected result
Linear quartiles: 3.5, 6.0, 8.5 minutes
The sample has four queue observations, so the median is between four and eight. Explicit method selection makes the calculation reproducible across tools that may use another convention. Report the sample size and collection window with the quantile, and avoid comparing two reports whose definitions differ.
Technical references: NumPy, Pandas and SciPy. For evaluation design see the scikit-learn guide to leakage; these examples do not require scikit-learn.