Measuring crime by weekday and year
Measuring crimes by weekday and by year simultaneously requires the functionality to pull this information from a Timestamp. Thankfully, this functionality is built into any Timestamp column with the .dt
attribute.
In this recipe, we will use the .dt
attribute to provide us with both the weekday name and year of each crime as a Series. We count all of the crimes by forming groups using both of these Series. Finally, we adjust the data to consider partial years and population before creating a heatmap of the total amount of crime.
How to do it…
- Read in the Denver crime hdf5 dataset leaving the
REPORTED_DATE
as a column:>>> crime = pd.read_hdf('data/crime.h5', 'crime') >>> crime OFFEN/PE_ID ... IS_TRAFFIC 0 traffic-accident-dui-duid ... 1 1 vehicular-eluding-no-chase ... 0 2 disturbing-the-peace .....