python笔记:4.1.1.1统计量_集中趋势_均值_截尾均值、缩尾均值、几何平均数、调和平均数

# -*- coding: utf-8 -*-
"""
Created on Sun May 26 14:22:25 2019

@author: User
"""
import pandas as pd
from scipy import stats

jddf=pd.read_csv('data\stock.csv',sep=',',header=None,
                   names=['id','time','code','open_p','colse_p','low_p','vol','high_p','col'])
print(jddf.head())

print("\n 计算截尾均值 stats.tmean(jddf['open_p']):")
print(stats.tmean(jddf['open_p']))

print("\n 指定数据范围,计算截尾均值 stats.tmean(jddf['open_p'],(4.41,4.47)):")
print(stats.tmean(jddf['open_p'],(4.41,4.47)))

print("\n 缩尾均值")
print("stats.mstats.winsorize(jddf['open_p'],(0.05,0.05)).mean():")
print(stats.mstats.winsorize(jddf['open_p'],(0.05,0.05)).mean())

print("\n 几何平均数 stats.gmean(jddf['open_p']):")
print(stats.gmean(jddf['open_p']))

print("\n 调和平均数 stats.hmean(jddf['open_p']):")
print(stats.hmean(jddf['open_p']))

运行:

   id      time    code  open_p  colse_p  low_p       vol  high_p     col
0   1  20130902  600028    4.41     4.43   4.37  17275.39    4.41  392662
1   2  20130903  600028    4.41     4.46   4.40  19241.84    4.45  434177
2   3  20130904  600028    4.44     4.49   4.42  20106.30    4.47  451470
3   4  20130905  600028    4.47     4.48   4.42  15582.48    4.47  349997
4   5  20130906  600028    4.46     4.52   4.45  19101.41    4.50  425777

 计算截尾均值 stats.tmean(jddf['open_p']):
5.658718703976436

 指定数据范围,计算截尾均值 stats.tmean(jddf['open_p'],(4.41,4.47)):
4.4393548387096775

 缩尾均值
stats.mstats.winsorize(jddf['open_p'],(0.05,0.05)).mean():
5.643718703976435

 几何平均数 stats.gmean(jddf['open_p']):
5.599208830471792

 调和平均数 stats.hmean(jddf['open_p']):
5.541704395121767
 

你可能感兴趣的:(python学习)