# -*- coding: utf-8 -*-
"""
Created on Fri Feb 17 11:30:57 2017
@author: yunjinqi
E-mail:yunjinqi@qq.com
Differentiate yourself in the world from anyone else.
"""
import pandas as pd
df=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 sts
import numpy as np
len(rate)#长度
rate.mean()#均值
rate.std()#标准差
rate.var()#var
rate.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))
时间序列分析(2)Python-基本统计量的计算
最新推荐文章于 2024-05-10 11:54:28 发布