Pandas datetime rounding: dt.floor, dt.ceil, and dt.round

Pandas datetime rounding: dt.floor, dt.ceil, and dt.round

Want to round Python Pandas datetimes? You have 3 options:

– dt.floor — earlier
– dt.ceil – later
– dt.round — nearest

For example:

s.dt.floor('3h')  # previous multiple-of-3 hour
s.dt.ceil('15m')  # next 15-minute block
s.dt.round('1D')  # nearest 1 day