typestar

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

  1. describe returns a named tuple of the usual moments.
  2. trim_mean drops the tails before averaging.
  3. iqr and median_abs_deviation resist outliers.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 3 in Distributions, step 3 of 23 in Scientific computing with SciPy.

← Previous Next →