我就废话不多说了,直接上代码吧!
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 22 17:03:16
@author: yunjinqi
E-mail:yunjinqi@
Differentiate yourself in the world from anyone else.
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.tsa.stattools as ts
import statsmodels.api as sm
from statsmodels.graphics.api import qqplot
from statsmodels.sandbox.stats.runs import runstest_1samp
import scipy.stats as sts
namelist=['cu','al','zn','pb','sn','au','ag','rb','hc','bu','ru','m9','y9','a9',
'p9','c9','cs','jd','l9','v9','pp','j9','jm','i9','sr','cf',
'zc','fg','ta','ma','oi','rm','sm']
j=0
for i in namelist:
filename='C:/Users/HXWD/Desktop/数据/'+i+'.csv'
data=pd.read_csv(filename,encoding='gbk')
data.columns=['date','open','high','low','close','amt','opi']
data.head()
data=np.log(data['close'])
r=data-data.shift(1)
r=r.dropna()
#print(r)
rate = np.array(list(r))
print('品种{}数据长度{}均值{}标准差{}方差{}偏度{}峰度{}'.format(i,len(rate),
rate.mean(),rate.std(),rate.var(),sts.skew(rate),
sts.kurtosis(rate)))
#结果
品种cu数据长度4976均值0.00012152573153376814标准差0.014276535327917023方差0.0002038194609692628偏度-0.16028824462338614峰度2.642455989417427
品种al数据长度5406均值-2.3195089066551237e-05标准差0.009053990835143359方差8.197475004285994e-05偏度-0.34748915595295604峰度5.083890815632417
品种zn数据长度2455均值-0.00011823058103745542标准差0.016294570963077237方差0.00026551304287075983偏度-0.316153612624431峰度1.7208737518119293
品种pb数据长度1482均值-9.866770650275384e-05标准差0.011417348325010642方差0.0001303558427746233偏度-0.21599833469407717峰度5.878332673854807
品种sn数据长度510均值0.00034131697514080907标准差0.013690993291257949方差0.00018744329730127014偏度0.024808842588775293峰1.072347367872859
品种au数据长度2231均值0.0001074021979121701标准差0.012100456199756058方差0.00014642104024221482偏度-0.361814930575112峰度4.110915875328322
品种ag数据长度1209均值-0.0003262089978362889标准差0.014853094655086982方差0.00022061442083297348偏度-0.2248883178719188峰度4.296247290616826
品种rb数据长度1966均值-6.984154093694264e-05标准差0.013462363746262961方差0.00018123523763669528偏度0.07827546016742666峰度5.198115698123077
品种hc数据长度758均值-7.256339078572361e-05标准差0.01710980071993581方差0.000292745280675916偏度-0.08403481899486816峰度3.6250669416786323
品种bu数据长度864均值-0.0006258998207218544标准差0.01716581014361468方差0.0002946650378866246偏度-0.41242405508236435峰度2.437556911829674
品种ru数据长度4827均值5.17426767764321e-05标准差0.016747187916000945方差0.00028046830309384806偏度-0.1986573449586119峰度1.736876616149547
品种m9数据长度4058均值8.873778774208505e-05标准差0.012812626470272115方差0.0001641633970667177偏度-0.12119836197638824峰度2.159984922606264
品种y9数据长度2748均值4.985975458693667e-05标准差0.012855191360434762方差0.00016525594491339655偏度-0.33456507243405786峰度2.566586342814616
品种a9数据长度5392均值9.732600802295795e-05标准差0.010601259945310599方差0.00011238671242804687偏度-0.08768586026629852峰度3.898562231789457
品种p9数据长度2311均值-0.00021108840931287863标准差0.014588073181583774方差0.00021281187915124373偏度-0.2881364812318466峰度1.693401619226936
品种c9数据长度3075均值0.00010060972262212708标准差0.007206853641314312方差5.1938739407325355e-05偏度-5.204419912904765e-05峰6.074899127691497
品种cs数据长度573均值-0.0006465907683602394标准差0.011237570390237955方差0.00012628298827555283偏度0.10170996173895988峰度1.176384982024672
品种jd数据长度847均值-9.035290965408637e-05标准差0.01167344224455134方差0.00013626925383687581偏度-0.0682866825422671峰度2.0899893901516133
品种l9数据长度2370均值-0.00014710186232216803标准差0.014902467199956509方差0.00022208352864577958偏度-0.2105262196327885峰度1.8796065573836
品种v9数据长度1927均值-5.190379527562386e-05标准差0.010437020362123387方差0.00010893139403937818偏度-0.050531345744352064峰度3.47595007264211
品种pp数据长度773均值-0.0003789841804842144标准差0.01439578332841083方差0.00020723857763855122偏度0.05479337073436029峰度1.3397870170464232
品种j9数据长度1468均值-0.00021854062264841954标准差0.01639429047795793方差0.000268772760275662偏度-0.10048542944058193峰度5.156597958913997
品种jm数据长度997均值-0.00011645794468155402标准差0.01792430947223131方差0.000321280870056321偏度0.0010592028961588294峰度3.743159578760195
品种i9数据长度862均值-0.0007372124442033161标准差0.021187573227350754方差0.0004489132592643504偏度0.00014411506989559858峰度1.585951370650
品种sr数据长度2749均值0.00012213466321006727标准差0.012183745931527473方差0.00014844366492401223偏度-0.038613285961243735峰度2.51613626
品种cf数据长度3142均值2.517526768612e-05标准差0.010657271857464626方差0.00011357744344390753偏度-0.034412876065561426峰度5.6421501855702
品种zc数据长度475均值0.00041282070613302206标准差0.015170141171075784方差0.00023013318315036853偏度-0.1393361750238265峰度1.2533894316392926
品种fg数据长度1068均值-1.57490340832121e-05标准差0.013148411070446203方差0.00017288071367743227偏度0.008980132282547534峰度1.9028507879273144
品种ta数据长度2518均值-0.00023122774877981512标准差0.013637519813532077方差0.00018598194666447998偏度-0.9126347458178135峰度10.954670464918
品种ma数据长度700均值-0.00024988691257348835标准差0.015328611435734359方差0.00023496632854772616偏度0.0164362832185746峰度1.1736088397060
品种oi数据长度1098均值-0.0004539513793265549标准差0.009589990427720812方差9.196791640377678e-05偏度-0.28987574371279706峰度3.871322266527967
品种rm数据长度1049均值1.458523923966432e-05标准差0.013432556545527753方差0.00018043357534880047偏度-0.053300026893851014峰度1.3938292783638
品种sm数据长度548均值-3.179600698107184e-05标准差0.020018458278106444方差0.00040073867183228846偏度-2.6734390275887647峰度31.533801188366837
#正态分布的偏度应该是0,峰度是3,所以,不满者这些的都是非标准正态分布
以上这篇python 实现检验33品种数据是否是正态分布就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。