There's more...

It is possible to use resample even when the index does not contain a Timestamp. You can use the on parameter to select the column with Timestamps that will be used to form groups:

>>> crime = pd.read_hdf('data/crime.h5', 'crime')
>>> weekly_crimes2 = crime.resample('W', on='REPORTED_DATE').size()
>>> weekly_crimes2.equals(weekly_crimes)
True

Similarly, this is possible using groupby with pd.Grouper by selecting the Timestamp column with the key parameter:

>>> weekly_crimes_gby2 = crime.groupby(pd.Grouper(key='REPORTED_DATE', 
freq='W')).size()
>>> weekly_crimes_gby2.equals(weekly_crimes_gby)
True

We can also easily produce a line plot of all the crimes in Denver (including traffic accidents) by calling the plot method on our Series of weekly crimes:

>>> weekly_crimes.plot(figsize=(16, 4), title='All Denver Crimes')
..................Content has been hidden....................

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