Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
pd.timedelta_range(start='2 day', periods=6)
Out[2]:
TimedeltaIndex(['2 days', '3 days', '4 days', '5 days', '6 days', '7 days'], dtype='timedelta64[ns]', freq='D')

The closed parameter specifies which endpoint is included. The default behavior is to include both endpoints.

In [5]:
pd.timedelta_range(start='2 day', periods=5, closed='right')
Out[5]:
TimedeltaIndex(['3 days', '4 days', '5 days', '6 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.

In [6]:
pd.timedelta_range(start='2 day', end='3 days', freq='6H')
Out[6]:
TimedeltaIndex(['2 days 00:00:00', '2 days 06:00:00', '2 days 12:00:00',
                '2 days 18:00:00', '3 days 00:00:00'],
               dtype='timedelta64[ns]', freq='6H')

Specify start, end, and periods; the frequency is generated automatically (linearly spaced).

In [7]:
pd.timedelta_range(start='2 day', end='5 days', periods=4)
Out[7]:
TimedeltaIndex(['2 days', '3 days', '4 days', '5 days'], dtype='timedelta64[ns]', freq=None)