pandas.TimedeltaIndex.round#

TimedeltaIndex.round(freq, ambiguous='raise', nonexistent='raise')[source]#

Perform round operation on the data to the specified freq.

This method rounds each timedelta value in the Series/Index to the nearest specified frequency using standard rounding rules (round half to even).

Parameters:
freqstr or Offset

The frequency level to round the index to. Must be a fixed frequency like ‘s’ (second) not ‘ME’ (month end). See frequency aliases for a list of possible freq values.

ambiguous‘infer’, bool-ndarray, ‘NaT’, default ‘raise’

Accepted for compatibility with DatetimeIndex.round(); has no effect since TimedeltaIndex values are never tz-aware.

nonexistent‘shift_forward’, ‘shift_backward’, ‘NaT’, timedelta, default ‘raise’

Accepted for compatibility with DatetimeIndex.round(); has no effect since TimedeltaIndex values are never tz-aware.

Returns:
TimedeltaIndex

Values rounded to the given freq.

Raises:
ValueError if the freq cannot be converted.

See also

TimedeltaIndex.floor

Perform floor operation on the data to the specified freq.

TimedeltaIndex.ceil

Perform ceil operation on the data to the specified freq.

Examples

>>> tdelta_idx = pd.timedelta_range("1 day", periods=3, freq="6h20min")
>>> tdelta_idx
TimedeltaIndex(['1 days 00:00:00', '1 days 06:20:00', '1 days 12:40:00'],
               dtype='timedelta64[us]', freq='380min')
>>> tdelta_idx.round("h")
TimedeltaIndex(['1 days 00:00:00', '1 days 06:00:00', '1 days 13:00:00'],
               dtype='timedelta64[us]', freq=None)