Chp05 - Statistics


In [26]:
# statistics, pg 97
import random
from collections import Counter
import matplotlib.pyplot as plt

In [21]:
num_friends = [random.randint(0, 100) for _ in range(100)]

In [22]:
print num_friends


[0, 25, 17, 60, 63, 30, 63, 38, 52, 53, 97, 80, 54, 14, 62, 91, 72, 43, 18, 19, 34, 38, 15, 49, 7, 91, 31, 90, 23, 46, 40, 76, 39, 49, 61, 2, 56, 18, 19, 91, 54, 71, 45, 52, 70, 88, 89, 44, 72, 40, 7, 16, 90, 65, 95, 94, 18, 67, 26, 85, 66, 74, 26, 93, 47, 16, 35, 42, 93, 90, 99, 58, 91, 44, 64, 4, 11, 73, 41, 46, 28, 31, 42, 53, 83, 46, 37, 84, 29, 91, 65, 18, 60, 84, 43, 79, 59, 56, 17, 2]

In [23]:
friend_counts = Counter(num_friends)
xs = range(101)
ys = [friend_counts[x] for x in xs]

In [24]:
print ys


[1, 0, 2, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 1, 1, 2, 2, 4, 2, 0, 0, 0, 1, 0, 1, 2, 0, 1, 1, 1, 2, 0, 0, 1, 1, 0, 1, 2, 1, 2, 1, 2, 2, 2, 1, 3, 1, 0, 2, 0, 0, 2, 2, 2, 0, 2, 0, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 0, 0, 1, 1, 2, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 2, 1, 0, 0, 1, 1, 3, 5, 0, 2, 1, 1, 0, 1, 0, 1, 0]

In [29]:
plt.bar(xs, ys)
plt.axis([0, 101, 0, 6])
plt.title("Hist of Friend Counts")
plt.xlabel("# of Friends")
plt.ylabel("# of people")

plt.show()



In [33]:
# number of data points
num_points = len(num_friends)

# max and min values
max_point = max(num_friends)
min_point = min(num_friends)

print num_points, max_point, min_point


100 99 0

In [ ]:


In [ ]:


In [ ]: