How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time? How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time? pandas pandas

How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time?


Liam's link looks great, but also check out pandas.Timedelta - looks like it plays nicely with NumPy's and Python's time deltas.

https://pandas.pydata.org/pandas-docs/stable/timedeltas.html

pd.date_range('2014-01-01', periods=10) + pd.Timedelta(days=1)


This one worked for me:

>> print(df)                          TotalVolume  Symbol2016-04-15 09:00:00       108400       2802.T2016-04-15 09:05:00       50300        2802.T>> print(df.set_index(pd.to_datetime(df.index.values) - datetime(2016, 4, 15)))             TotalVolume  Symbol09:00:00     108400       2802.T09:05:00     50300        2802.T


The Philippe solution but cleaner:

My subtraction data is: '2018-09-22T11:05:00.000Z'

import datetimeimport pandas as pddf_modified = pd.to_datetime(df_reference.index.values) - datetime.datetime(2018, 9, 22, 11, 5, 0)