欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2019年09月06日 08:43:37   作者:cakincqm  
這篇文章主要介紹了Python統(tǒng)計分析模塊statistics用法,結(jié)合實例形式分析了Python統(tǒng)計分析模塊statistics計算平均數(shù)、中位數(shù)、出現(xiàn)次數(shù)、標(biāo)準差等相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了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"<pyshell#27>", line 1,in<module>
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(),返回總體標(biāo)準差(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ù)學(xué)運算技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進階經(jīng)典教程

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

相關(guān)文章

  • Python實現(xiàn)批量上傳本地maven庫到nexus

    Python實現(xiàn)批量上傳本地maven庫到nexus

    這篇文章主要為大家詳細介紹了如何使用Python實現(xiàn)批量上傳本地maven庫到nexus,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的小伙伴可以參考下
    2024-01-01
  • python執(zhí)行js腳本報錯CryptoJS is not defined問題

    python執(zhí)行js腳本報錯CryptoJS is not defined問題

    這篇文章主要介紹了python執(zhí)行js腳本報錯CryptoJS is not defined問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • Pandas替換NaN值的方法實現(xiàn)

    Pandas替換NaN值的方法實現(xiàn)

    本文主要介紹了Pandas替換NaN值的方法實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • 在Pycharm terminal中字體大小設(shè)置的方法

    在Pycharm terminal中字體大小設(shè)置的方法

    今天小編就為大家分享一篇在Pycharm terminal中字體大小設(shè)置的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • 基于注解實現(xiàn) SpringBoot 接口防刷的方法

    基于注解實現(xiàn) SpringBoot 接口防刷的方法

    這篇文章主要介紹了基于注解實現(xiàn) SpringBoot 接口防刷的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Python走樓梯問題解決方法示例

    Python走樓梯問題解決方法示例

    這篇文章主要介紹了Python走樓梯問題解決方法,結(jié)合實例形式分析了Python基于遞歸與迭代思想解決走樓梯問題的相關(guān)操作技巧,需要的朋友可以參考下
    2018-07-07
  • python的open函數(shù)常見用法

    python的open函數(shù)常見用法

    python打開文件使用open()函數(shù),返回一個指向文件的指針,這篇文章主要介紹了python的open函數(shù)使用,需要的朋友可以參考下
    2022-11-11
  • 介紹Python中的文檔測試模塊

    介紹Python中的文檔測試模塊

    這篇文章主要介紹了Python中的文檔測試模塊,代碼基于Python2.x版本,需要的朋友可以參考下
    2015-04-04
  • 使用python telnetlib批量備份交換機配置的方法

    使用python telnetlib批量備份交換機配置的方法

    今天小編就為大家分享一篇使用python telnetlib批量備份交換機配置的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • Python 對Excel求和、合并居中的操作

    Python 對Excel求和、合并居中的操作

    這篇文章主要介紹了Python 對Excel求和、合并居中的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03

最新評論