How to properly add hours to a pandas.tseries.index.DatetimeIndex? How to properly add hours to a pandas.tseries.index.DatetimeIndex? pandas pandas

How to properly add hours to a pandas.tseries.index.DatetimeIndex?


You can use pd.DateOffset:

test[1].index + pd.DateOffset(hours=16)

pd.DateOffset accepts the same keyword arguments as dateutil.relativedelta.


The problem you encountered was due to this bug which has been fixed in Pandas version 0.14.1:

In [242]: pd.to_timedelta(16, unit='h')Out[242]: numpy.timedelta64(16,'ns')

If you upgrade, your original code should work.