import scipy
import pandas as pd
import numpy as np
def Describe_Extend(data,ndigits):
result1 = pd.DataFrame(data.describe())
result2 = pd.DataFrame(data.mode().iloc[0,:])
result2.columns = ['mode']
Result = result1.append(result2.T)
def mode_pro(data):
mode0 = []
for i in data.columns:
if data[i].value_counts().max() !=1:
mode0.append(data[i].mode().values)
else:
a = [-9999.999]
mode0.append(a)
mode0 = pd.DataFrame(mode0,columns=['mode_pro']).T
mode0.columns =data.columns
return mode0
result21 = mode_pro(data)
Result = Result.append(result21)
result3 = pd.DataFrame(data.var())
result3.columns = ['var']
Result = Result.append(result3.T)
def Out_three_sigma(data):
out_count_list = []
for i in data.columns:
mean = data[i].mean()
std = data[i].std()
left = mean - 3*std
right = mean + 3*std
data2 = data[data[i].values > right]
data3 = data[data[i].values < left]
out_count = len(data2) + len(data3)
out_count_list.append(out_count)
Out_count_list = pd.DataFrame(out_count_list)
Out_count_list.columns = ['out 3 sigma']
return Out_count_list
Out_three_sigma = Out_three_sigma(data).T
Out_three_sigma.columns = data.columns
Result = Result.append(Out_three_sigma)
def Out_six_sigma(data):
out_count_list1 = []
for i in data.columns:
mean = data[i].mean()
std = data[i].std()
left = mean - 6*std
right = mean + 6*std
data1 = data[data[i].values > right ]
data2 = data[data[i].values < left]
out_count1 = len(data1) + len(data2)
out_count_list1.append(out_count1)
Out_count_list1 = pd.DataFrame(out_count_list1)
Out_count_list1.columns = ['out 6 sigma']
return Out_count_list1
Out_six_sigma = Out_six_sigma(data).T
Out_six_sigma.columns = data.columns
Result = Result.append(Out_six_sigma)
result4 = pd.DataFrame(data.skew())
result4.columns = ['skew']
Result = Result.append(result4.T)
result5 = pd.DataFrame(data.kurt())
result5.columns = ['kurt']
Result = Result.append(result5.T)
result6 = pd.DataFrame(data.mad())
result6.columns = ['mad']
Result = Result.append(result6.T)
Result = round(Result,ndigits)
return Result
Describe_Extend(data,3)
Describe_Extend
最新推荐文章于 2023-12-12 12:21:50 发布