# -*- coding: utf-8 -*-
import pandas as pd
from pandas import Series, DataFrame
import numpy as np
a=[98,83,65,72,79,76,75,94,91,77,63,83,89,69,64,78,63,86,91,72,71,72,70,80,65,70,62,74,71,76]
mean(a)
mean(np.sort(a)[14:16])
np.sort(a)
#求眾數(shù)的函數(shù)
def get_mode(arr):
mode = [];
arr_appear = dict((a, arr.count(a)) for a in arr); ?# 統(tǒng)計(jì)各個(gè)元素出現(xiàn)的次數(shù)
if max(arr_appear.values()) == 1: ?# 如果最大的出現(xiàn)為1
return; ?# 則沒(méi)有眾數(shù)
else:
for k, v in arr_appear.items(): ?# 否則膜蠢,出現(xiàn)次數(shù)最大的數(shù)字,就是眾數(shù)
if v == max(arr_appear.values()):
mode.append(k);
return mode;
get_mode(a)
var(a)
std(a)
a=Series(a)
a.skew()
a.kurt()
a.describe()
df = DataFrame({'data1' : np.random.randn(5),
'data2' : np.random.randn(5)})
df.cov()
df.corr()
###假設(shè)檢驗(yàn)
from scipy import stats as ss
df=DataFrame({'data':[10.1,10,9.8,10.5,9.7,10.1,9.9,10.2,10.3,9.9]})
ss.ttest_1samp(a = df, popmean = 10)