Examples
Parsing a single string to a Timedelta:

In [1]:
import numpy as np
import pandas as pd
In [2]:
pd.to_timedelta('2 days 04:06:10.00006')
Out[2]:
Timedelta('2 days 04:06:10.000060')
In [3]:
pd.to_timedelta('20.5us')
Out[3]:
Timedelta('0 days 00:00:00.000020')

Parsing a list or array of strings:

In [4]:
pd.to_timedelta(['2 days 04:06:10.00006', '15.5us', 'nan'])
Out[4]:
TimedeltaIndex(['2 days 04:06:10.000060', '0 days 00:00:00.000015', NaT], dtype='timedelta64[ns]', freq=None)

Converting numbers by specifying the unit keyword argument:

In [5]:
pd.to_timedelta(np.arange(6), unit='s')
Out[5]:
TimedeltaIndex(['00:00:00', '00:00:01', '00:00:02', '00:00:03', '00:00:04',
                '00:00:05'],
               dtype='timedelta64[ns]', freq=None)
In [6]:
pd.to_timedelta(np.arange(6), unit='d')
Out[6]:
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days', '5 days'], dtype='timedelta64[ns]', freq=None)

Returning an ndarray by using the ‘box’ keyword argument:

In [7]:
pd.to_timedelta(np.arange(6), box=False)
Out[7]:
array([0, 1, 2, 3, 4, 5], dtype='timedelta64[ns]')