I have a variable with 3 timestamps.
a = DatetimeIndex(['2016-01-26 20:30:00', '2016-01-26 21:30:00','2016-01-26 22:30:00'],
dtype='datetime64[ns]', freq='H')
I've now since learned that the round function rounds according to these rules "when halfway between two integers the even integer is chosen."
a.round('H')
DatetimeIndex(['2016-01-26 20:00:00', '2016-01-26 22:00:00','2016-01-26 22:00:00'],
dtype='datetime64[ns]', freq=None)
How I can make sure it rounds all 30 minute timestamps (e.g. 20:30, 19:30) to the next hour.
Thanks!
Edit:
I have tried the following function from Pandas Timestamp rounds 30 seconds inconsistently
def half_up_minute(x):
m = (x - x.floor('H')).total_seconds() < 30 # Round True Down, False Up
return x.where(m).floor('H').fillna(x.ceil('H'))
but get the following error:
TypeError: 'value' must be a scalar, passed: DatetimeIndex