Skip to content

Commit 32427c5

Browse files
committed
statistics模块
statistics模块
1 parent cac9570 commit 32427c5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

day043-statistics/statistics.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#计算平均数
2+
>>> statistics.mean([1, 2, 3, 4, 5])
3+
4+
>>> from fractions import Fraction as F
5+
>>> statistics.mean([F(4, 7), F(4, 21), F(5, 4), F(1, 4)])
6+
7+
>>> from decimal import Decimal as D
8+
>>> statistics.mean([D("0.5"), D("0.78"), D("0.88"), D("0.988")])
9+
10+
11+
#计算调和平均数
12+
>>> statistics.harmonic_mean([4, 5, 7])
13+
14+
15+
#计算中值
16+
>>> statistics.median([1, 4, 7])
17+
18+
>>> statistics.median([1, 4, 7, 10])
19+
20+
21+
#计算中小值
22+
>>> statistics.median_low([1, 4, 7])
23+
24+
>>> statistics.median_low([1, 4, 7, 10])
25+
26+
27+
#计算中大值
28+
>>> statistics.median_high([1, 4, 7])
29+
30+
>>> statistics.median_high([1, 4, 7, 10])
31+
32+
33+
#计算中位数
34+
>>> statistics.median_grouped([1, 2, 2, 3, 4, 4, 4, 4, 4, 5])
35+
36+
>>> statistics.median_grouped([3, 4, 4, 5, 6], interval=1)
37+
38+
>>> statistics.median_grouped([1, 3, 5, 5, 7], interval=2)
39+
40+
41+
#计算众数
42+
>>> statistics.mode([1, 1, 2, 3, 3, 3, 3, 4])
43+
44+
>>> statistics.mode(["red", "blue", "blue", "blue", "green", "green", "red"])

0 commit comments

Comments
 (0)