How it works...

In step 1, we read in our data and place a column of Timestamps into the index to create a DatetimeIndex. In step 2, we see that a DatetimeIndex has lots of the same functionality that a single Timestamp object has. In step 3, we directly use these extra features of the DatetimeIndex to extract the weekday name.

In step 4, we take advantage of the special ability of the groupby method to accept a function that is passed the DatetimeIndex. The x in the anonymous function is literally the DatetimeIndex and we use it to retrieve the weekday name. It is possible to pass groupby a list of any number of custom functions, as done in step 5. Here, the first function uses the round DatetimeIndex method to round each value to the nearest second hour. The second function retrieves the year. After the grouping and aggregating, we unstack the years as columns. We then highlight the maximum value of each column. Crime is reported most often between 3 and 5 p.m. Most traffic accidents occur between 5 p.m. and 7 p.m.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.38