Skip to main content
`Ctrl`+`K`

# Time deltas

Timedeltas are differences in times, expressed in difference units, e.g. days, hours, minutes, seconds. They can be both positive and negative.

`Timedelta` is a subclass of `datetime.timedelta`, and behaves in a similar manner, but allows compatibility with `np.timedelta64` types as well as a host of custom representation, parsing, and attributes.

## Parsing

You can construct a `Timedelta` scalar through various arguments, including ISO 8601 Duration strings.

    In [1]: import datetime

    # strings
    In [2]: pd.Timedelta("1 days")
    Out[2]: Timedelta('1 days 00:00:00')

    In [3]: pd.Timedelta("1 days 00:00:00")
    Out[3]: Timedelta('1 days 00:00:00')

    In [4]: pd.Timedelta("1 days 2 hours")
    Out[4]: Timedelta('1 days 02:00:00')

    In [5]: pd.Timedelta("-1 days 2 min 3us")
    Out[5]: Timedelta('-2 days +23:57:59.999997')

    # like datetime.timedelta
    # note: these MUST be specified as keyword arguments
    In [6]: pd.Timedelta(days=1, seconds=1)
    Out[6]: Timedelta('1 days 00:00:01')

    # integers with a unit
    In [7]: pd.Timedelta(1, unit="D")
    Out[7]: Timedelta('1 days 00:00:00')

    # from a datetime.timedelta/np.timedelta64
    In [8]: pd.Timedelta(datetime.timedelta(days=1, seconds=1))
    Out[8]: Timedelta('1 days 00:00:01')

    In [9]: pd.Timedelta(np.timedelta64(1, "ms"))
    Out[9]: Timedelta('0 days 00:00:00.001000')

    # negative Timedeltas have this string repr
    # to be more consistent with datetime.timedelta conventions
    In [10]: pd.Timedelta("-1us")
    Out[10]: Timedelta('-1 days +23:59:59.999999')

    # a NaT
    In [11]: pd.Timedelta("nan")
    Out[11]: NaT

    In [12]: pd.Timedelta("nat")
    Out[12]: NaT

    # ISO 8601 Duration strings
    In [13]: pd.Timedelta("P0DT0H1M0S")
    Out[13]: Timedelta('0 days 00:01:00')

    In [14]: pd.Timedelta("P0DT0H0M0.000000123S")
    Out[14]: Timedelta('0 days 00:00:00.000000123')

DateOffsets (`Hour, Minute, Second, Milli, Micro, Nano`) can also be used in construction.

    In [15]: pd.Timedelta(pd.offsets.Second(2))
    Out[15]: Timedelta('0 days 00:00:02')

Further, operations among the scalars yield another scalar `Timedelta`.

    In [16]: pd.Timedelta(pd.offsets.Hour(48)) + pd.Timedelta(pd.offsets.Second(2)) + pd.Timedelta(
       ....:     "00:00:00.000123"
       ....: )
       ....:
    Out[16]: Timedelta('2 days 00:00:02.000123')

### to_timedelta

Using the top-level `pd.to_timedelta`, you can convert a scalar, array, list, or Series from a recognized timedelta format / value into a `Timedelta` type. It will construct Series if the input is a Series, a scalar if the input is scalar-like, otherwise it will output a `TimedeltaIndex`.

You can parse a single string to a Timedelta:

    In [17]: pd.to_timedelta("1 days 06:05:01.00003")
    Out[17]: Timedelta('1 days 06:05:01.000030')

    In [18]: pd.to_timedelta("15.5us")
    Out[18]: Timedelta('0 days 00:00:00.000015500')

or a list/array of strings:

    In [19]: pd.to_timedelta(["1 days 06:05:01.00003", "15.5us", "nan"])
    Out[19]:
    TimedeltaIndex(['1 days 06:05:01.000030000', '0 days 00:00:00.000015500', NaT],
                   dtype='timedelta64[ns]', freq=None)

The `unit` keyword argument specifies the unit of the Timedelta if the input is numeric:

    In [20]: pd.to_timedelta(np.arange(5), unit="s")
    Out[20]:
    TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02',
                    '0 days 00:00:03', '0 days 00:00:04'],
                   dtype='timedelta64[s]', freq=None)

    In [21]: pd.to_timedelta(np.arange(5), unit="D")
    Out[21]:
    TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[s]', freq=None)

Warning

If a string or array of strings is passed as an input then the `unit` keyword argument will be ignored. If a string without units is passed then the default unit of nanoseconds is assumed.

### Timedelta limitations

`Timedelta` uses a 64-bit integer to represent time, so the representable range depends on the chosen resolution (`unit`). The class-level attributes `Timedelta.min`, `Timedelta.max`, and `Timedelta.resolution` default to nanosecond limits:

    In [22]: pd.Timedelta.min
    Out[22]: Timedelta('-106752 days +00:12:43.145224193')

    In [23]: pd.Timedelta.max
    Out[23]: Timedelta('106751 days 23:47:16.854775807')

    In [24]: pd.Timedelta.resolution
    Out[24]: Timedelta('0 days 00:00:00.000000001')

On a `Timedelta` instance, the same attributes reflect the bounds and step size of that instance’s resolution:

    In [25]: td = pd.Timedelta(1, unit="s")

    In [26]: td.min
    Out[26]: Timedelta('-106751991167301 days +08:29:53')

    In [27]: td.max
    Out[27]: Timedelta('106751991167300 days 15:30:07')

    In [28]: td.resolution
    Out[28]: Timedelta('0 days 00:00:01')

Different resolutions can be converted to each other through `Timedelta.as_unit()`.

## Operations

You can operate on Series/DataFrames and construct `timedelta64[ns]` Series through subtraction operations on `datetime64[ns]` Series, or `Timestamps`.

    In [29]: s = pd.Series(pd.date_range("2012-1-1", periods=3, freq="D"))

    In [30]: td = pd.Series([pd.Timedelta(days=i) for i in range(3)])

    In [31]: df = pd.DataFrame({"A": s, "B": td})

    In [32]: df
    Out[32]:
               A      B
    0 2012-01-01 0 days
    1 2012-01-02 1 days
    2 2012-01-03 2 days

    In [33]: df["C"] = df["A"] + df["B"]

    In [34]: df
    Out[34]:
               A      B          C
    0 2012-01-01 0 days 2012-01-01
    1 2012-01-02 1 days 2012-01-03
    2 2012-01-03 2 days 2012-01-05

    In [35]: df.dtypes
    Out[35]:
    A     datetime64[us]
    B    timedelta64[us]
    C     datetime64[us]
    dtype: object

    In [36]: s - s.max()
    Out[36]:
    0   -2 days
    1   -1 days
    2    0 days
    dtype: timedelta64[us]

    In [37]: s - datetime.datetime(2011, 1, 1, 3, 5)
    Out[37]:
    0   364 days 20:55:00
    1   365 days 20:55:00
    2   366 days 20:55:00
    dtype: timedelta64[us]

    In [38]: s + datetime.timedelta(minutes=5)
    Out[38]:
    0   2012-01-01 00:05:00
    1   2012-01-02 00:05:00
    2   2012-01-03 00:05:00
    dtype: datetime64[us]

    In [39]: s + pd.offsets.Minute(5)
    Out[39]:
    0   2012-01-01 00:05:00
    1   2012-01-02 00:05:00
    2   2012-01-03 00:05:00
    dtype: datetime64[us]

    In [40]: s + pd.offsets.Minute(5) + pd.offsets.Milli(5)
    Out[40]:
    0   2012-01-01 00:05:00.005
    1   2012-01-02 00:05:00.005
    2   2012-01-03 00:05:00.005
    dtype: datetime64[us]

Operations with scalars from a `timedelta64[ns]` series:

    In [41]: y = s - s[0]

    In [42]: y
    Out[42]:
    0   0 days
    1   1 days
    2   2 days
    dtype: timedelta64[us]

Series of timedeltas with `NaT` values are supported:

    In [43]: y = s - s.shift()

    In [44]: y
    Out[44]:
    0      NaT
    1   1 days
    2   1 days
    dtype: timedelta64[us]

Elements can be set to `NaT` using `np.nan` analogously to datetimes:

    In [45]: y[1] = np.nan

    In [46]: y
    Out[46]:
    0      NaT
    1      NaT
    2   1 days
    dtype: timedelta64[us]

Operands can also appear in a reversed order (a singular object operated with a Series):

    In [47]: s.max() - s
    Out[47]:
    0   2 days
    1   1 days
    2   0 days
    dtype: timedelta64[us]

    In [48]: datetime.datetime(2011, 1, 1, 3, 5) - s
    Out[48]:
    0   -365 days +03:05:00
    1   -366 days +03:05:00
    2   -367 days +03:05:00
    dtype: timedelta64[us]

    In [49]: datetime.timedelta(minutes=5) + s
    Out[49]:
    0   2012-01-01 00:05:00
    1   2012-01-02 00:05:00
    2   2012-01-03 00:05:00
    dtype: datetime64[us]

`min, max` and the corresponding `idxmin, idxmax` operations are supported on frames:

    In [50]: A = s - pd.Timestamp("20120101") - pd.Timedelta("00:05:05")

    In [51]: B = s - pd.Series(pd.date_range("2012-1-2", periods=3, freq="D"))

    In [52]: df = pd.DataFrame({"A": A, "B": B})

    In [53]: df
    Out[53]:
                      A       B
    0 -1 days +23:54:55 -1 days
    1   0 days 23:54:55 -1 days
    2   1 days 23:54:55 -1 days

    In [54]: df.min()
    Out[54]:
    A   -1 days +23:54:55
    B   -1 days +00:00:00
    dtype: timedelta64[us]

    In [55]: df.min(axis=1)
    Out[55]:
    0   -1 days
    1   -1 days
    2   -1 days
    dtype: timedelta64[us]

    In [56]: df.idxmin()
    Out[56]:
    A    0
    B    0
    dtype: int64

    In [57]: df.idxmax()
    Out[57]:
    A    2
    B    0
    dtype: int64

`min, max, idxmin, idxmax` operations are supported on Series as well. A scalar result will be a `Timedelta`.

    In [58]: df.min().max()
    Out[58]: Timedelta('-1 days +23:54:55')

    In [59]: df.min(axis=1).min()
    Out[59]: Timedelta('-1 days +00:00:00')

    In [60]: df.min().idxmax()
    Out[60]: 'A'

    In [61]: df.min(axis=1).idxmin()
    Out[61]: 0

You can fillna on timedeltas, passing a timedelta to get a particular value.

    In [62]: y.fillna(pd.Timedelta(0))
    Out[62]:
    0   0 days
    1   0 days
    2   1 days
    dtype: timedelta64[us]

    In [63]: y.fillna(pd.Timedelta(10, unit="s"))
    Out[63]:
    0   0 days 00:00:10
    1   0 days 00:00:10
    2   1 days 00:00:00
    dtype: timedelta64[us]

    In [64]: y.fillna(pd.Timedelta("-1 days, 00:00:05"))
    Out[64]:
    0   -1 days +00:00:05
    1   -1 days +00:00:05
    2     1 days 00:00:00
    dtype: timedelta64[us]

You can also negate, multiply and use `abs` on `Timedeltas`:

    In [65]: td1 = pd.Timedelta("-1 days 2 hours 3 seconds")

    In [66]: td1
    Out[66]: Timedelta('-2 days +21:59:57')

    In [67]: -1 * td1
    Out[67]: Timedelta('1 days 02:00:03')

    In [68]: -td1
    Out[68]: Timedelta('1 days 02:00:03')

    In [69]: abs(td1)
    Out[69]: Timedelta('1 days 02:00:03')

## Reductions

Numeric reduction operation for `timedelta64[ns]` will return `Timedelta` objects. As usual `NaT` are skipped during evaluation.

    In [70]: y2 = pd.Series(
       ....:     pd.to_timedelta(["-1 days +00:00:05", "nat", "-1 days +00:00:05", "1 days"])
       ....: )
       ....:

    In [71]: y2
    Out[71]:
    0   -1 days +00:00:05
    1                 NaT
    2   -1 days +00:00:05
    3     1 days 00:00:00
    dtype: timedelta64[us]

    In [72]: y2.mean()
    Out[72]: Timedelta('-1 days +16:00:03.333334')

    In [73]: y2.median()
    Out[73]: Timedelta('-1 days +00:00:05')

    In [74]: y2.quantile(0.1)
    Out[74]: Timedelta('-1 days +00:00:05')

    In [75]: y2.sum()
    Out[75]: Timedelta('-1 days +00:00:10')

## Frequency conversion

Timedelta Series and `TimedeltaIndex`, and `Timedelta` can be converted to other frequencies by astyping to a specific timedelta dtype.

    In [76]: december = pd.Series(pd.date_range("20121201", periods=4))

    In [77]: january = pd.Series(pd.date_range("20130101", periods=4))

    In [78]: td = january - december

    In [79]: td[2] += datetime.timedelta(minutes=5, seconds=3)

    In [80]: td[3] = np.nan

    In [81]: td
    Out[81]:
    0   31 days 00:00:00
    1   31 days 00:00:00
    2   31 days 00:05:03
    3                NaT
    dtype: timedelta64[us]

    # to seconds
    In [82]: td.astype("timedelta64[s]")
    Out[82]:
    0   31 days 00:00:00
    1   31 days 00:00:00
    2   31 days 00:05:03
    3                NaT
    dtype: timedelta64[s]

For timedelta64 resolutions other than the supported “s”, “ms”, “us”, “ns”, an alternative is to divide by another timedelta object. Note that division by the NumPy scalar is true division, while astyping is equivalent of floor division.

    # to days
    In [83]: td / np.timedelta64(1, "D")
    Out[83]:
    0    31.000000
    1    31.000000
    2    31.003507
    3          NaN
    dtype: float64

Dividing or multiplying a `timedelta64[ns]` Series by an integer or integer Series yields another `timedelta64[ns]` dtypes Series.

    In [84]: td * -1
    Out[84]:
    0   -31 days +00:00:00
    1   -31 days +00:00:00
    2   -32 days +23:54:57
    3                  NaT
    dtype: timedelta64[us]

    In [85]: td * pd.Series([1, 2, 3, 4])
    Out[85]:
    0   31 days 00:00:00
    1   62 days 00:00:00
    2   93 days 00:15:09
    3                NaT
    dtype: timedelta64[us]

Rounded division (floor-division) of a `timedelta64[ns]` Series by a scalar `Timedelta` gives a series of integers.

    In [86]: td // pd.Timedelta(days=3, hours=4)
    Out[86]:
    0    9.0
    1    9.0
    2    9.0
    3    NaN
    dtype: float64

    In [87]: pd.Timedelta(days=3, hours=4) // td
    Out[87]:
    0    0.0
    1    0.0
    2    0.0
    3    NaN
    dtype: float64

The mod (%) and divmod operations are defined for `Timedelta` when operating with another timedelta-like or with a numeric argument.

    In [88]: pd.Timedelta(hours=37) % datetime.timedelta(hours=2)
    Out[88]: Timedelta('0 days 01:00:00')

    # divmod against a timedelta-like returns a pair (int, Timedelta)
    In [89]: divmod(datetime.timedelta(hours=2), pd.Timedelta(minutes=11))
    Out[89]: (10, Timedelta('0 days 00:10:00'))

    # divmod against a numeric returns a pair (Timedelta, Timedelta)
    In [90]: divmod(pd.Timedelta(hours=25), 86400000000000)
    Out[90]: (Timedelta('0 days 00:00:00'), Timedelta('1 days 01:00:00'))

## Attributes

You can access various components of the `Timedelta` or `TimedeltaIndex` directly using the attributes `days,seconds,microseconds,nanoseconds`. These are identical to the values returned by `datetime.timedelta`, in that, for example, the `.seconds` attribute represents the number of seconds >= 0 and < 1 day. These are signed according to whether the `Timedelta` is signed.

These operations can also be directly accessed via the `.dt` property of the `Series` as well.

Note

Note that the attributes are NOT the displayed values of the `Timedelta`. Use `.components` to retrieve the displayed values.

For a `Series`:

    In [91]: td.dt.days
    Out[91]:
    0    31.0
    1    31.0
    2    31.0
    3     NaN
    dtype: float64

    In [92]: td.dt.seconds
    Out[92]:
    0      0.0
    1      0.0
    2    303.0
    3      NaN
    dtype: float64

You can access the value of the fields for a scalar `Timedelta` directly.

    In [93]: tds = pd.Timedelta("31 days 5 min 3 sec")

    In [94]: tds.days
    Out[94]: 31

    In [95]: tds.seconds
    Out[95]: 303

    In [96]: (-tds).seconds
    Out[96]: 86097

You can use the `.components` property to access a reduced form of the timedelta. This returns a `DataFrame` indexed similarly to the `Series`. These are the displayed values of the `Timedelta`.

    In [97]: td.dt.components
    Out[97]:
       days  hours  minutes  seconds  milliseconds  microseconds  nanoseconds
    0  31.0    0.0      0.0      0.0           0.0           0.0          0.0
    1  31.0    0.0      0.0      0.0           0.0           0.0          0.0
    2  31.0    0.0      5.0      3.0           0.0           0.0          0.0
    3   NaN    NaN      NaN      NaN           NaN           NaN          NaN

    In [98]: td.dt.components.seconds
    Out[98]:
    0    0.0
    1    0.0
    2    3.0
    3    NaN
    Name: seconds, dtype: float64

You can convert a `Timedelta` to an ISO 8601 Duration string with the `.isoformat` method

    In [99]: pd.Timedelta(
       ....:     days=6, minutes=50, seconds=3, milliseconds=10, microseconds=10, nanoseconds=12
       ....: ).isoformat()
       ....:
    Out[99]: 'P6DT0H50M3.010010012S'

## TimedeltaIndex

To generate an index with time delta, you can use either the `TimedeltaIndex` or the `timedelta_range()` constructor.

Using `TimedeltaIndex` you can pass string-like, `Timedelta`, `timedelta`, or `np.timedelta64` objects. Passing `np.nan/pd.NaT/nat` will represent missing values.

    In [100]: pd.TimedeltaIndex(
       .....:     [
       .....:         "1 days",
       .....:         "1 days, 00:00:05",
       .....:         np.timedelta64(2, "D"),
       .....:         datetime.timedelta(days=2, seconds=2),
       .....:     ]
       .....: )
       .....:
    Out[100]:
    TimedeltaIndex(['1 days 00:00:00', '1 days 00:00:05', '2 days 00:00:00',
                    '2 days 00:00:02'],
                   dtype='timedelta64[us]', freq=None)

The string ‘infer’ can be passed in order to set the frequency of the index as the inferred frequency upon creation:

    In [101]: pd.TimedeltaIndex(["0 days", "10 days", "20 days"], freq="infer")
    Out[101]:
    TimedeltaIndex(['0 days', '10 days', '20 days'], dtype='timedelta64[us]',
                   freq='10D')

### Generating ranges of time deltas

Similar to `date_range()`, you can construct regular ranges of a `TimedeltaIndex` using `timedelta_range()`. The default frequency for `timedelta_range` is calendar day:

    In [102]: pd.timedelta_range(start="1 days", periods=5)
    Out[102]:
    TimedeltaIndex(['1 days', '2 days', '3 days', '4 days', '5 days'],
                   dtype='timedelta64[us]', freq='D')

Various combinations of `start`, `end`, and `periods` can be used with `timedelta_range`:

    In [103]: pd.timedelta_range(start="1 days", end="5 days")
    Out[103]:
    TimedeltaIndex(['1 days', '2 days', '3 days', '4 days', '5 days'],
                   dtype='timedelta64[us]', freq='D')

    In [104]: pd.timedelta_range(end="10 days", periods=4)
    Out[104]:
    TimedeltaIndex(['7 days', '8 days', '9 days', '10 days'],
                   dtype='timedelta64[us]', freq='D')

The `freq` parameter can passed a variety of frequency aliases:

    In [105]: pd.timedelta_range(start="1 days", end="2 days", freq="30min")
    Out[105]:
    TimedeltaIndex(['1 days 00:00:00', '1 days 00:30:00', '1 days 01:00:00',
                    '1 days 01:30:00', '1 days 02:00:00', '1 days 02:30:00',
                    '1 days 03:00:00', '1 days 03:30:00', '1 days 04:00:00',
                    '1 days 04:30:00', '1 days 05:00:00', '1 days 05:30:00',
                    '1 days 06:00:00', '1 days 06:30:00', '1 days 07:00:00',
                    '1 days 07:30:00', '1 days 08:00:00', '1 days 08:30:00',
                    '1 days 09:00:00', '1 days 09:30:00', '1 days 10:00:00',
                    '1 days 10:30:00', '1 days 11:00:00', '1 days 11:30:00',
                    '1 days 12:00:00', '1 days 12:30:00', '1 days 13:00:00',
                    '1 days 13:30:00', '1 days 14:00:00', '1 days 14:30:00',
                    '1 days 15:00:00', '1 days 15:30:00', '1 days 16:00:00',
                    '1 days 16:30:00', '1 days 17:00:00', '1 days 17:30:00',
                    '1 days 18:00:00', '1 days 18:30:00', '1 days 19:00:00',
                    '1 days 19:30:00', '1 days 20:00:00', '1 days 20:30:00',
                    '1 days 21:00:00', '1 days 21:30:00', '1 days 22:00:00',
                    '1 days 22:30:00', '1 days 23:00:00', '1 days 23:30:00',
                    '2 days 00:00:00'],
                   dtype='timedelta64[us]', freq='30min')

    In [106]: pd.timedelta_range(start="1 days", periods=5, freq="2D5h")
    Out[106]:
    TimedeltaIndex(['1 days 00:00:00', '3 days 05:00:00', '5 days 10:00:00',
                    '7 days 15:00:00', '9 days 20:00:00'],
                   dtype='timedelta64[us]', freq='53h')

Specifying `start`, `end`, and `periods` will generate a range of evenly spaced timedeltas from `start` to `end` inclusively, with `periods` number of elements in the resulting `TimedeltaIndex`:

    In [107]: pd.timedelta_range("0 days", "4 days", periods=5)
    Out[107]:
    TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[us]', freq=None)

    In [108]: pd.timedelta_range("0 days", "4 days", periods=10)
    Out[108]:
    TimedeltaIndex(['0 days 00:00:00', '0 days 10:40:00', '0 days 21:20:00',
                    '1 days 08:00:00', '1 days 18:40:00', '2 days 05:20:00',
                    '2 days 16:00:00', '3 days 02:40:00', '3 days 13:20:00',
                    '4 days 00:00:00'],
                   dtype='timedelta64[us]', freq=None)

### Using the TimedeltaIndex

Similarly to other of the datetime-like indices, `DatetimeIndex` and `PeriodIndex`, you can use `TimedeltaIndex` as the index of pandas objects.

    In [109]: s = pd.Series(
       .....:     np.arange(100),
       .....:     index=pd.timedelta_range("1 days", periods=100, freq="h"),
       .....: )
       .....:

    In [110]: s
    Out[110]:
    1 days 00:00:00     0
    1 days 01:00:00     1
    1 days 02:00:00     2
    1 days 03:00:00     3
    1 days 04:00:00     4
                       ..
    4 days 23:00:00    95
    5 days 00:00:00    96
    5 days 01:00:00    97
    5 days 02:00:00    98
    5 days 03:00:00    99
    Freq: h, Length: 100, dtype: int64

Selections work similarly, with coercion on string-likes and slices:

    In [111]: s["1 day":"2 day"]
    Out[111]:
    1 days 00:00:00     0
    1 days 01:00:00     1
    1 days 02:00:00     2
    1 days 03:00:00     3
    1 days 04:00:00     4
                       ..
    2 days 19:00:00    43
    2 days 20:00:00    44
    2 days 21:00:00    45
    2 days 22:00:00    46
    2 days 23:00:00    47
    Freq: h, Length: 48, dtype: int64

    In [112]: s["1 day 01:00:00"]
    Out[112]: np.int64(1)

    In [113]: s[pd.Timedelta("1 day 1h")]
    Out[113]: np.int64(1)

Furthermore you can use partial string selection and the range will be inferred:

    In [114]: s["1 day":"1 day 5 hours"]
    Out[114]:
    1 days 00:00:00    0
    1 days 01:00:00    1
    1 days 02:00:00    2
    1 days 03:00:00    3
    1 days 04:00:00    4
    1 days 05:00:00    5
    Freq: h, dtype: int64

### Operations

Finally, the combination of `TimedeltaIndex` with `DatetimeIndex` allow certain combination operations that are NaT preserving:

    In [115]: tdi = pd.TimedeltaIndex(["1 days", pd.NaT, "2 days"])

    In [116]: tdi.to_list()
    Out[116]: [Timedelta('1 days 00:00:00'), NaT, Timedelta('2 days 00:00:00')]

    In [117]: dti = pd.date_range("20130101", periods=3)

    In [118]: dti.to_list()
    Out[118]:
    [Timestamp('2013-01-01 00:00:00'),
     Timestamp('2013-01-02 00:00:00'),
     Timestamp('2013-01-03 00:00:00')]

    In [119]: (dti + tdi).to_list()
    Out[119]: [Timestamp('2013-01-02 00:00:00'), NaT, Timestamp('2013-01-05 00:00:00')]

    In [120]: (dti - tdi).to_list()
    Out[120]: [Timestamp('2012-12-31 00:00:00'), NaT, Timestamp('2013-01-01 00:00:00')]

### Conversions

Similarly to frequency conversion on a `Series` above, you can convert these indices to yield another Index.

    In [121]: tdi / np.timedelta64(1, "s")
    Out[121]: Index([86400.0, nan, 172800.0], dtype='float64')

    In [122]: tdi.astype("timedelta64[s]")
    Out[122]: TimedeltaIndex(['1 days', NaT, '2 days'], dtype='timedelta64[s]', freq=None)

Scalars type ops work as well. These can potentially return a different type of index.

    # adding or timedelta and date -> datelike
    In [123]: tdi + pd.Timestamp("20130101")
    Out[123]:
    DatetimeIndex(['2013-01-02', 'NaT', '2013-01-03'], dtype='datetime64[us]',
                  freq=None)

    # subtraction of a date and a timedelta -> datelike
    # note that trying to subtract a date from a Timedelta will raise an exception
    In [124]: (pd.Timestamp("20130101") - tdi).to_list()
    Out[124]: [Timestamp('2012-12-31 00:00:00'), NaT, Timestamp('2012-12-30 00:00:00')]

    # timedelta + timedelta -> timedelta
    In [125]: tdi + pd.Timedelta("10 days")
    Out[125]: TimedeltaIndex(['11 days', NaT, '12 days'], dtype='timedelta64[us]', freq=None)

    # division can result in a Timedelta if the divisor is an integer
    In [126]: tdi / 2
    Out[126]:
    TimedeltaIndex(['0 days 12:00:00', NaT, '1 days 00:00:00'],
                   dtype='timedelta64[us]', freq=None)

    # or a float64 Index if the divisor is a Timedelta
    In [127]: tdi / tdi[0]
    Out[127]: Index([1.0, nan, 2.0], dtype='float64')

## Resampling

Similar to timeseries resampling, we can resample with a `TimedeltaIndex`.

    In [128]: s.resample("D").mean()
    Out[128]:
    1 days    11.5
    2 days    35.5
    3 days    59.5
    4 days    83.5
    5 days    97.5
    Freq: D, dtype: float64