8000 Code for statistics. · reloadbrain/practice-python@a0febcf · GitHub
[go: up one dir, main page]

Skip to content

Commit a0febcf

Browse files
committed
Code for statistics.
1 parent 45a7e89 commit a0febcf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

data-science/statistics.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import Counter
2+
from matplotlib import pyplot as plt
3+
import random
4+
5+
6+
def friend_hist():
7+
num_friends = [random.randint(1, 120) for _ in range(1025)]
8+
9+
friend_counts = Counter(num_friends)
10+
xs = range(101) # largest value is 100
11+
ys = [friend_counts[x] for x in xs] # height is just # of friends
12+
plt.bar(xs, ys)
13+
plt.axis([0, 101, 0, 25])
14+
plt.title("Histogram of Friend Counts")
15+
plt.xlabel("# of friends")
16+
plt.ylabel("# of people")
17+
plt.show()
18+
19+
20+
def main():
21+
friend_hist()
22+
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)
0