Select Date And Time Ranges
Goal¶
This post aims to introduce how to select a subset of the pandas
dataframe by selecting a date range.
Libraries¶
import pandas as pd
import numpy as np
Create a dataframe¶
date_ranges = pd.date_range('20190101', '20191231', freq='d')
df_rand = pd.DataFrame({'date': date_ranges,
'value': np.random.random(date_ranges.shape[0])})
df_rand.head()
Select a range using .between
¶
df_rand.loc[df_rand.date.between('20190201', '20190211'),:]