summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2021-02-08 16:22:32 -0500
committerBryan Brattlof <hello@bryanbrattlof.com>2021-02-10 16:12:41 -0500
commit7c4875976c49d95f4f8869697c2bf41c9d0962e1 (patch)
tree30ec499ad572419b2af467f5d3c23bed6d485d6c
parent49304f2f0f60172dbff5f280a6443dd22d12152b (diff)
downloadboston-parking-tickets-7c4875976c49d95f4f8869697c2bf41c9d0962e1.tar.gz
boston-parking-tickets-7c4875976c49d95f4f8869697c2bf41c9d0962e1.tar.bz2
add code to generate tickets grouped by year
-rw-r--r--tickets-per-year.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tickets-per-year.py b/tickets-per-year.py
new file mode 100644
index 0000000..8eb2f71
--- /dev/null
+++ b/tickets-per-year.py
@@ -0,0 +1,33 @@
+#
+# How many tickets are issued in Boston per year
+#
+import matplotlib.patheffects as pe
+import matplotlib.pyplot as plt
+
+import pandas as pd
+import numpy as np
+import utils
+
+data = utils.data
+
+byr = data.groupby(pd.Grouper(key="Issued", freq="Y"))["Issued"].count()
+#byr.describe()
+
+# Dropping 2020 as an outlier
+byr19 = byr.drop(pd.Timestamp('20201231'))
+#byr19.describe()
+
+fig, ax = plt.subplots()
+plt.bar(x=byr.index.year, height=byr.values, color="black")
+
+# fit trend line (excluding 2020 data)
+fit = np.poly1d(np.polyfit(byr19.index.year, byr19.values, 1))
+plt.plot(byr.index.year, fit(byr.index.year), color='tab:red', lw=3)
+
+ax.set(
+ title="Tickets Issued per Year",
+ ylabel="Tickets Issued (Million)")
+
+plt.savefig(
+ utils.FIG_DIR / "tickets-per-year.svg",
+ transparent=True)