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
39
40
41
42
43
44
45
|
#
# How many tickets are issued in Boston per day of week?
#
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import utils
data = utils.data
#data.info()
# group all tickets by day of week
bdow = data.groupby(pd.Grouper(key="Issued", freq="D"))["Issued"].count()
fig, ax = plt.subplots()
# drop 2020 data
covid = bdow[bdow.index.year == 2020]
bdow.drop(covid.index, inplace=True)
# plot the median and average tickets issued per day of week
med = bdow.groupby(bdow.index.dayofweek).median()
std = bdow.groupby(bdow.index.dayofweek).std()
# add median +- standard deviation
plt.fill_between(range(7), med-std, med+std, facecolor="white")
# plt.plot(range(7), med, color="black")
# plot each total for that day (2020 in red)
plt.scatter(x=covid.index.dayofweek, y=covid, color="tab:red",
alpha=0.2, label="2020")
plt.scatter(x=bdow.index.dayofweek, y=bdow, color="black",
alpha=0.2, label="11-19")
plt.xticks(range(7), ["Mon", "Tue", "Wen", "Thu", "Fri", "Sat", "Sun"])
plt.legend(loc="upper right")
ax.set(
title="Tickets Issued on each Day",
ylabel="Tickets Issued")
plt.tight_layout()
plt.savefig(
utils.FIG_DIR / "tickets-by-day-of-week.svg",
transparent=True)
|