陳鍾誠

Version 1.0

敘述統計

參考 – https://docs.python.org/3/library/statistics.html

基本統計值

$ python

>>> from statistics import *
>>> mean([1, 2, 3, 4, 4])
2.8
>>> from fractions import Fraction as F
>>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
Fraction(13, 21)
>>> median([1, 3, 5])
3
>>> median([1, 3, 5, 7])
4.0
>>> mode([1, 1, 2, 3, 3, 3, 3, 4])
3
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
'red'
>>> a = [1.5, 2.5, 2.5, 2.75, 3.25, 4.75] 
>>> pstdev(a)                                 
0.986893273527251
>>> pvariance(a)
0.9739583333333334
>>> sqrt(pvariance(a))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sqrt' is not defined
>>> import math
>>> math.sqrt(pvariance(a))
0.986893273527251