首页 > 编程 > Python > 正文

时间序列分析(2)Python-基本统计量的计算

2019-11-08 03:18:02
字体:
来源:转载
供稿:网友
# -*- coding: utf-8 -*-"""Created on Fri Feb 17 11:30:57 2017@author: yunjinqiE-mail:yunjinqi@QQ.comDifferentiate yourself in the world from anyone else."""import pandas as pddf=pd.read_Excel('luowen.xls')df.head()df=df.iloc[::,8]df.head()df.shift(1).head()rate=(df-df.shift(1))/df.shift(1)rate=rate.dropna()rate.head()############################################计算数据的基本统计量:均值,方差,偏度,峰度等import stats as stsimport numpy as nplen(rate)#长度rate.mean()#均值rate.std()#标准差rate.var()#varrate.describe()#描述sts.skewness(rate)sts.kurtosis(rate)###引用别人写的scores=rate#集中趋势的度量  PRint('求和:',np.sum(scores))  print('个数:',len(scores))  print('平均值:',np.mean(scores))  print('中位数:',np.median(scores))  print('众数:',sts.mode(scores))  print('上四分位数',sts.quantile(scores,p=0.25))  print('下四分位数',sts.quantile(scores,p=0.75))  #离散趋势的度量  print('最大值:',np.max(scores))  print('最小值:',np.min(scores))  print('极差:',np.max(scores)-np.min(scores))  print('四分位差',sts.quantile(scores,p=0.75)-sts.quantile(scores,p=0.25))  print('标准差:',np.std(scores))  print('方差:',np.var(scores))  print('离散系数:',np.std(scores)/np.mean(scores))  #偏度与峰度的度量  print('偏度:',sts.skewness(scores))  print('峰度:',sts.kurtosis(scores))
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表