0

I have a datetime index dataframe. I want to add a few hours to it. My code:

from datetime import datetime,timedelta
 df.index = 
DatetimeIndex(['2019-10-01 06:58:45', '2019-10-01 06:59:00',
               '2019-10-01 06:59:15', '2019-10-01 06:59:30',
               '2020-07-18 09:16:30', '2020-07-18 09:16:45'],
              dtype='datetime64[ns]', name='',freq=None)
# add two hours to the index datetime
df.index = df.index.time+timedelta(hours=2)

Present output:

TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta'
Mainland
  • 4,110
  • 3
  • 25
  • 56

1 Answers1

4

Do not need call time

df.index = df.index + pd.Timedelta('2 hour')
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Can you have a look at https://stackoverflow.com/questions/64200777/python-matplotlib-one-colorbar-for-various-subplots-with-various-ranges – Mainland Oct 04 '20 at 23:25