pandas.Timedelta.round#

Timedelta.round(freq)#

Round the Timedelta to the specified resolution.

Rounds the Timedelta value to the nearest multiple of the given frequency using half-even rounding.

Parameters:
freqstr or timedelta

Frequency string or timedelta value indicating the rounding resolution. It uses the same units as class constructor Timedelta.

Returns:
a new Timedelta rounded to the given resolution of freq
Raises:
ValueError if the freq cannot be converted

See also

Timedelta.floor

Floor the Timedelta to the specified resolution.

Timedelta.ceil

Ceil the Timedelta to the specified resolution.

Timestamp.round

Similar method for Timestamp objects.

Examples

>>> td = pd.Timedelta('1001ms')
>>> td
Timedelta('0 days 00:00:01.001000')
>>> td.round('s')
Timedelta('0 days 00:00:01')

freq can also be a timedelta value:

>>> td.round(freq=pd.Timedelta('1s'))
Timedelta('0 days 00:00:01')