pandas.timedelta_range(start=None, end=None, periods=None, freq=None, name=None, closed=None)
[source]
Return a fixed frequency TimedeltaIndex, with day as the default frequency
Parameters: |
|
---|---|
Returns: |
|
Of the four parameters start
, end
, periods
, and freq
, exactly three must be specified. If freq
is omitted, the resulting TimedeltaIndex
will have periods
linearly spaced elements between start
and end
(closed on both sides).
To learn more about the frequency strings, please see this link.
>>> pd.timedelta_range(start='1 day', periods=4) TimedeltaIndex(['1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq='D')
The closed
parameter specifies which endpoint is included. The default behavior is to include both endpoints.
>>> pd.timedelta_range(start='1 day', periods=4, closed='right') TimedeltaIndex(['2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq='D')
The freq
parameter specifies the frequency of the TimedeltaIndex. Only fixed frequencies can be passed, non-fixed frequencies such as ‘M’ (month end) will raise.
>>> pd.timedelta_range(start='1 day', end='2 days', freq='6H') TimedeltaIndex(['1 days 00:00:00', '1 days 06:00:00', '1 days 12:00:00', '1 days 18:00:00', '2 days 00:00:00'], dtype='timedelta64[ns]', freq='6H')
Specify start
, end
, and periods
; the frequency is generated automatically (linearly spaced).
>>> pd.timedelta_range(start='1 day', end='5 days', periods=4) TimedeltaIndex(['1 days 00:00:00', '2 days 08:00:00', '3 days 16:00:00', '5 days 00:00:00'], dtype='timedelta64[ns]', freq=None)
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.timedelta_range.html