n m
n m

Reputation: 79

Change Date in TimeSeries Dataframes Python

I am trying to change the date part of an hourly time series. I am doing this by using this method.

import numpy as np
import pandas as pd

np.random.seed(0)
df_volume = pd.DataFrame(np.random.randint(60, 100, (24,4)), index=pd.date_range('2015-08-11', periods=24, freq='H'), columns='Col1 Col2 Col3 Col4'.split())

#df_volume.reset_index(inplace=True)
df_volume.index = pd.to_datetime('2015-01-01') + pd.to_datetime(df_volume.index,format='%H:%M:%S')
print (df_volume)

The error says raise NotImplementedError. I dont know how to solve this. If i reset_index and then try to change the date, the error is time data 0 does not match format '%H:%M:%S' (match). Please help. I have 24 hours worth of data and i want to change the date and keep the hours the way they are.

Upvotes: 1

Views: 48

Answers (1)

johnchase
johnchase

Reputation: 13705

I am not exactly sure what you are trying to do, however it sounds like you want to change the days of the index without changing the hours, minutes or seconds. If that is what you are looking for this should do it. You can change the days or months for what you need.

from pandas.tseries.offsets import DateOffset
df_volume.index = df_volume.index - DateOffset(months=7, days=10)

Upvotes: 1

Related Questions