>>importstatistics>>>statistics.mean([1,2,3,4,5,6,7,8,9])#使用整數(shù)列表做參數(shù)5>>>statistics.mean(range(1,10))#使用range對象做參數(shù)5>>>importfractions>>>x=[(3,7),(1,21),(5,3),(1,3)]>>>y=" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Python統(tǒng)計分析模塊statistics用法示例

系統(tǒng) 2063 0

本文實例講述了Python統(tǒng)計分析模塊statistics用法。分享給大家供大家參考,具體如下:

一 計算平均數(shù)函數(shù)mean()

            
>>>import statistics
>>> statistics.mean([1,2,3,4,5,6,7,8,9])#使用整數(shù)列表做參數(shù)
5
>>> statistics.mean(range(1,10))#使用range對象做參數(shù)
5
>>>import fractions
>>> x =[(3,7),(1,21),(5,3),(1,3)]
>>> y =[fractions.Fraction(*item)for item in x]
>>> y
[Fraction(3,7),Fraction(1,21),Fraction(5,3),Fraction(1,3)]
>>> statistics.mean(y)#使用包含分數(shù)的列表做參數(shù)
Fraction(13,21)
>>>import decimal
>>> x =('0.5','0.75','0.625','0.375')
>>> y = map(decimal.Decimal, x)
>>> statistics.mean(y)
Decimal('0.5625')


          

二 中位數(shù)函數(shù)median()、median_low()、median_high()、median_grouped()

            
>>> statistics.median([1,3,5,7])#偶數(shù)個樣本時取中間兩個數(shù)的平均數(shù)
4.0
>>> statistics.median_low([1,3,5,7])#偶數(shù)個樣本時取中間兩個數(shù)的較小者
3
>>> statistics.median_high([1,3,5,7])#偶數(shù)個樣本時取中間兩個數(shù)的較大者
5
>>> statistics.median(range(1,10))
5
>>> statistics.median_low([5,3,7]), statistics.median_high([5,3,7])
(5,5)
>>> statistics.median_grouped([5,3,7])
5.0
>>> statistics.median_grouped([52,52,53,54])
52.5
>>> statistics.median_grouped([1,3,3,5,7])
3.25
>>> statistics.median_grouped([1,2,2,3,4,4,4,4,4,5])
3.7
>>> statistics.median_grouped([1,2,2,3,4,4,4,4,4,5], interval=2)
3.4


          

三 返回最常見數(shù)據(jù)或出現(xiàn)次數(shù)最多的數(shù)據(jù)(most common data)的函數(shù)mode()

            
>>> statistics.mode([1,3,5,7])#無法確定出現(xiàn)次數(shù)最多的唯一元素
Traceback(most recent call last):
File"
            
              ", line 1,in
              
                
statistics.mode([1,3,5,7])#無法確定出現(xiàn)次數(shù)最多的唯一元素
File"D:\Python36\lib\statistics.py", line 507,in mode
'no unique mode; found %d equally common values'% len(table)
statistics.StatisticsError: no unique mode; found 4 equally common values
>>> statistics.mode([1,3,5,7,3])
3
>>> statistics.mode(["red","blue","blue","red","green","red","red"])
'red'


              
            
          

四? pstdev(),返回總體標準差(population standard deviation ,the square root of the population variance)

            
>>> statistics.pstdev([1.5,2.5,2.5,2.75,3.25,4.75])
0.986893273527251
>>> statistics.pstdev(range(20))
5.766281297335398


          

五 pvariance(),返回總體方差(population variance)或二次矩(second moment)

            
>>> statistics.pvariance([1.5,2.5,2.5,2.75,3.25,4.75])
0.9739583333333334
>>> x =[1,2,3,4,5,10,9,8,7,6]
>>> mu = statistics.mean(x)
>>> mu
5.5
>>> statistics.pvariance([1,2,3,4,5,10,9,8,7,6], mu)
8.25
>>> statistics.pvariance(range(20))
33.25
>>> statistics.pvariance((random.randint(1,10000)for i in range(30)))
>>>import random
>>> statistics.pvariance((random.randint(1,10000)for i in range(30)))
7117280.4


          

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)學運算技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進階經(jīng)典教程》

希望本文所述對大家Python程序設計有所幫助。


更多文章、技術(shù)交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 玖玖色视频 | 1000部羞羞禁止免费观看视频 | 一区不卡在线观看 | 亚洲精品一区二区乱码在线观看 | 四虎影视成人永久在线播放 | 日本一级特黄毛片免费视频 | 第一福利视频 | 久久久久女人精品毛片 | 一级一片免费看 | 在线综合 亚洲 欧美中文字幕 | 好吊色青青青国产欧美日韩 | 久久日本精品国产精品白 | 精品国产国产综合精品 | 男女羞羞免费视频 | 国产精品永久免费视频观看 | 天天爱天天做久久天天狠狼 | 欧美一区二区三区成人看不卡 | 亚洲人妖女同在线播放 | 中文字幕日韩在线观看 | 亚洲国内精品久久 | 一级日本高清视频免费观看 | 久久这里有 | 老司机深夜福利影院 | 亚洲国产日韩a在线亚洲 | 日韩欧美无线在码 | 免费观看黄色的网站 | 亚洲一二区视频 | 91在线| 久青草国产视频 | 精品国产精品国产偷麻豆 | 日本精品视频网站 | 色婷婷综合在线视频最新 | 久久精品99久久香蕉国产色戒 | 妖精视频在线看免费视频 | 亚洲国产99| 国产婷婷色一区二区三区 | avav好色| 免费看aa | 日日躁夜夜躁狠狠天天 | 黄色影院在线观看视频 | 国产福利91|