How to do it...

  1. Read in the Denver crime hdf5 dataset leaving the REPORTED_DATE as a column:
>>> crime = pd.read_hdf('data/crime.h5', 'crime')>>> crime.head()
  1. All Timestamp columns have a special attribute called the dt accessor, which gives access to a variety of extra attributes and methods specifically designed for them. Let's find the weekday name of each REPORTED_DATE and then count these values:
>>> wd_counts = crime['REPORTED_DATE'].dt.weekday_name \                                         .value_counts()>>> wd_countsMonday       70024
Friday       69621
Wednesday    69538
Thursday     69287
Tuesday      68394
Saturday     58834
Sunday       55213
Name: REPORTED_DATE, dtype: int64
  1. The weekends appear ...

Get Pandas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.