Time-based selection and filtering

Let's do a quick recap of datetime slicing as we discuss some of the additional functionality that the pandas time series have. We can easily isolate data for the year by indexing on it: fb['2018']. In the case of our stock data, the full dataframe would be returned because we only have 2018 data; however, we can filter to a month (fb['2018-10']) or to a range of dates:

>>> fb['2018-10-11':'2018-10-15']

We only get three days back because the stock market is closed on the weekends:

open high low close volume trading_volume
date
2018-10-11 150.13 154.81 149.1600 153.35 35338901 low
2018-10-12 156.73 156.89 151.2998 153.74 25293492 low
2018-10-15 153.32 155.57 152.5500 153.52 15433521 ...

Get Hands-On Data Analysis with Pandas 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.