Examples
Parsing a single string to a Timedelta:
import numpy as np
import pandas as pd
pd.to_timedelta('2 days 04:06:10.00006')
pd.to_timedelta('20.5us')
Parsing a list or array of strings:
pd.to_timedelta(['2 days 04:06:10.00006', '15.5us', 'nan'])
Converting numbers by specifying the unit keyword argument:
pd.to_timedelta(np.arange(6), unit='s')
pd.to_timedelta(np.arange(6), unit='d')
Returning an ndarray by using the ‘box’ keyword argument:
pd.to_timedelta(np.arange(6), box=False)