October 2017
Intermediate to advanced
532 pages
16h 10m
English
In addition to the Timestamp and Timedelta data types, pandas offers the Period type to represent an exact time period. For example, 2012-05 would represent the entire month of May, 2012. You can manually construct a Period in the following manner:
>>> pd.Period(year=2012, month=5, day=17, hour=14, minute=20, freq='T')Period('2012-05-17 14:20', 'T')
This object represents the entire minute of May 17, 2012 at 2:20 p.m. It is possible to use these Periods in step 4 instead of grouping by date with pd.Grouper. DataFrames with a DatetimeIndex have the to_period method to convert Timestamps to Periods. It accepts an offset alias to determine the exact length of the time period.
>>> ad_period = crime_sort.groupby([lambda x: x.to_period('M'), ...Read now
Unlock full access