summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2021-02-09 19:14:09 -0500
committerBryan Brattlof <hello@bryanbrattlof.com>2021-02-10 16:13:52 -0500
commitfa6a09d39b71b24217a2c76e0f2fcbbe26664a84 (patch)
treeed76402f2a74d5022a69f79ad5d5ec978e03d90b
parent1f08e57c85508e28515c8a48c43b57c460116b96 (diff)
downloadboston-parking-tickets-fa6a09d39b71b24217a2c76e0f2fcbbe26664a84.tar.gz
boston-parking-tickets-fa6a09d39b71b24217a2c76e0f2fcbbe26664a84.tar.bz2
add code to generate tickets by day-of-week graphic
-rw-r--r--tickets-per-day-of-week.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tickets-per-day-of-week.py b/tickets-per-day-of-week.py
new file mode 100644
index 0000000..c36b398
--- /dev/null
+++ b/tickets-per-day-of-week.py
@@ -0,0 +1,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)