Here is a heatmap showing the number of crimes per district and days of week according to City of Boston's public data for the first 3 months of 2022:
Below is the code..
table_pivot= data.pivot_table("Hour",
["DISTRICT"],
columns="DAY_OF_WEEK",
aggfunc = "count")
column_order = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
table_pivot2 = table_pivot.reindex(column_order, axis=1)
table_pivot2=table_pivot2.drop("External", axis=0)
cmap = sns.cm.rocket_r
sns.set(rc = {'figure.figsize':(15,8)})
sns.heatmap(table_pivot2,
annot = True,
fmt="0.1f",
linewidths=.8,
vmin=-0.05,
cmap = cmap,)
["DISTRICT"],
columns="DAY_OF_WEEK",
aggfunc = "count")
column_order = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
table_pivot2 = table_pivot.reindex(column_order, axis=1)
table_pivot2=table_pivot2.drop("External", axis=0)
cmap = sns.cm.rocket_r
sns.set(rc = {'figure.figsize':(15,8)})
sns.heatmap(table_pivot2,
annot = True,
fmt="0.1f",
linewidths=.8,
vmin=-0.05,
cmap = cmap,)
Note: "hour" is counted in pivot table because it doesn't have a null value.
Hiç yorum yok:
Yorum Gönder