path: root/
blob: c36b3989a6cefc0ae7a3d49e49160c43fc1e7822 (plain) (tree)

# 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 =

# 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")

    title="Tickets Issued on each Day",
    ylabel="Tickets Issued")

    utils.FIG_DIR / "tickets-by-day-of-week.svg",