Describing a sample in Python
describe, trimmed means and robust spread in one place.
import numpy as np
from scipy import stats
sample = np.array([88, 91, 97, 104, 99, 108, 92, 250])
summary = stats.describe(sample)
print(summary.nobs, round(summary.mean, 2), summary.minmax)
print(round(summary.skewness, 3), round(summary.kurtosis, 3))
print(round(stats.trim_mean(sample, 0.125), 2))
print(stats.iqr(sample), round(stats.median_abs_deviation(sample), 2))
print(stats.zscore(sample).round(2)[:4])
How it works
describereturns a named tuple of the usual moments.trim_meandrops the tails before averaging.iqrandmedian_abs_deviationresist outliers.
Keywords and builtins used here
asprintround
The run, in numbers
- Lines
- 12
- Characters to type
- 415
- Tokens
- 134
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 80 seconds.
Step 3 of 3 in Distributions, step 3 of 23 in Scientific computing with SciPy.