forked from dabeaz-course/python-mastery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatarides.py
38 lines (30 loc) · 816 Bytes
/
datarides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# datarides.py
import tracemalloc
from collections import Counter
import readrides
tracemalloc.start()
rows = readrides.read_rides_as_dicts("Data/ctabus.csv")
print(len({row["route"] for row in rows}))
print(
[
row["rides"]
for row in rows
if row["route"] == "22" and row["date"] == "02/02/2011"
][0]
)
c = Counter()
for row in rows:
c[row["route"]] += row["rides"]
for route, count in c.most_common():
print("%5s %10d" % (route, count))
ini = Counter()
end = Counter()
for row in rows:
if "2001" in row["date"]:
ini[row["route"]] += row["rides"]
elif "2011" in row["date"]:
end[row["route"]] += row["rides"]
sub = end - ini
print(sub.most_common(5))
# ---- Memory use
print("Memory Use: Current %d, Peak %d" % tracemalloc.get_traced_memory())