Examples
Specifying the values
The next four examples generate the same DatetimeIndex, but vary the combination of start, end and periods.
Specify start and end, with the default daily frequency.
import numpy as np
import pandas as pd
pd.date_range(start='2/2/2019', end='2/08/2019')
Specify start and periods, the number of periods (days).
pd.date_range(start='2/2/2019', periods=8)
Specify end and periods, the number of periods (days).
pd.date_range(end='2/2/2019', periods=8)
Specify start, end, and periods; the frequency is generated automatically (linearly spaced).
pd.date_range(start='2019-06-20', end='2019-04-25', periods=4)
Other Parameters
Changed the freq (frequency) to 'M' (month end frequency).
pd.date_range(start='2/2/2019', periods=6, freq='M')
Multiples are allowed
pd.date_range(start='2/2/2019', periods=6, freq='3M')
freq can also be specified as an Offset object.
pd.date_range(start='2/2/2019', periods=6, freq=pd.offsets.MonthEnd(3))
Specify tz to set the timezone.
pd.date_range(start='2/2/2019', periods=6, tz='Asia/Tokyo')
closed controls whether to include start and end that are on the boundary. The default includes boundary points
on either end.
pd.date_range(start='2018-02-02', end='2018-02-05', closed=None)
Use closed='left' to exclude end if it falls on the boundary.
pd.date_range(start='2018-02-02', end='2018-02-05', closed='left')
Use closed='right' to exclude start if it falls on the boundary.
pd.date_range(start='2018-02-02', end='2018-02-05', closed='right')