statistics - Tukey five number summary in Python -
i have been unable find function in of standard packages, wrote 1 below. before throwing toward cheeseshop, however, know of published version? alternatively, please suggest improvements. thanks.
def fivenum(v): """returns tukey's 5 number summary (minimum, lower-hinge, median, upper-hinge, maximum) input vector, list or array of numbers based on 1.5 times interquartile distance""" import numpy np scipy.stats import scoreatpercentile try: np.sum(v) except typeerror: print('error: must provide list or array of numbers') q1 = scoreatpercentile(v,25) q3 = scoreatpercentile(v,75) iqd = q3-q1 md = np.median(v) whisker = 1.5*iqd return np.min(v), md-whisker, md, md+whisker, np.max(v),
pandas
series
, dataframe
have describe
method, similar r
's summary
:
in [3]: import numpy np in [4]: import pandas pd in [5]: s = pd.series(np.random.rand(100)) in [6]: s.describe() out[6]: count 100.000000 mean 0.540376 std 0.296250 min 0.002514 25% 0.268722 50% 0.593436 75% 0.831067 max 0.991971
nan
's handled correctly.
Comments
Post a Comment