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¶
In [2]:
import pandas as pd
import numpy as np
Create a dataframe¶
In [18]:
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()
Out[18]:
Select a range using .between
¶
In [19]:
df_rand.loc[df_rand.date.between('20190201', '20190211'),:]
Out[19]: