Pandas functions
Pandas Date Range β pd.date_range()
Create date ranges in pandas using pd.date_range
Think of Pandas Date Range (pd.date_range) like a βdate ruler.β You have a start time, end time, and interval frequency youβd like to split your dates by.
Donβt get intimidated by the βdateβ part, you can just as easily create time ranges as well. The frequency (how youβll split up your pd.date_range) is set by the offset options. Get familiar with these!
Youβll use pd.date_range when you need to have a clean series of dates to reindex your DataFrame.
Pseudo Code: Create a range of timestamps at a specified start and end.
Pandas Date Range
PD.Date_Range Parameters
- start β The timestamp that youβd like to start your date range
- end β The timestamp youβd like to end your date range
- periods (Optional) β Say instead of splitting your start/end times by 5 minute intervals, you just wanted to have 3 cuts. You can specify periods=3 and pandas will automatically cut your time for you.
- freq β The sub periods of time that you will cut your date range into. In the above image, we chose 6 hours (β6Hβ) to split our time by. This resulted in 4 buckets (24 hours in a day). See all the offset aliases here.
- Normalized (Optional) β Selecting Normalized will automatically set your start and end dates to midnight. This is useful when your start/end time has an hour specified, but you only care about the βdayβ information.
- Other Parameters β For a list of other lesser used parameters. Check out the official documentation.
Now the fun part, letβs take a look at a code sample