Slicing time series intelligently
DataFrame selection and slicing was covered previously. When the DataFrame has a DatetimeIndex
, even more opportunities arise for selection and slicing.
In this recipe, we will use partial date matching to select and slice a DataFrame with a DatetimeIndex
.
How to do it…
- Read in the Denver crimes dataset from the hdf5 file
crimes.h5
, and output the column data types and the first few rows. The hdf5 file format allows efficient storage of large amounts of data and is different from a CSV text file:>>> crime = pd.read_hdf('data/crime.h5', 'crime') >>> crime.dtypes OFFENSE_TYPE_ID category OFFENSE_CATEGORY_ID category REPORTED_DATE datetime64[ns] GEO_LON float64 GEO_LAT float64 NEIGHBORHOOD_ID category IS_CRIME int64 IS_TRAFFIC int64 dtype...