Trimmed Mean with Percentage Limit in Python?

前端 未结 3 778
感动是毒
感动是毒 2020-12-17 10:39

I am trying to calculate the trimmed mean, which excludes the outliers, of an array.

I found there is a module called scipy.stats.tmean, but it req

3条回答
  •  我在风中等你
    2020-12-17 11:15

    At least for scipy v0.14.0, there is a dedicated function for this (scipy.stats.trim_mean):

    from scipy import stats
    m = stats.trim_mean(X, 0.1) # Trim 10% at both ends
    

    which used stats.trimboth inside.

    From the source code it is possible to see that with proportiontocut=0.1 the mean will be calculated using 80% of the data. Note that the scipy.stats.trim_mean can not handle np.nan.

提交回复
热议问题