0

I want to adjust the timestamp of my time series dataframe. The existing date-time of the first row is 01/01/2001 04:30:00. I want to change it to 30/11/2011 19:30:00, and the rest (up to five years of 5 minutes record) should follow.

This is my code:

df['NewDateTime'] = df['DateTime'] + pd.Timedelta('3985 D')
df['NewDateTime'] = df['NewDateTime'] + pd.Timedelta('15h')

This gives correct result for the first rows. But I believe that the result will be wrong if the timestamp adjustment span is more than 4 years because there are Februaries with the number of days of 28 while other Februaries have 29 days.

How is the correct way to do it?

This is the data.

k.ko3n
  • 954
  • 8
  • 26
  • What specifically are you trying to achieve? If you want to add exactly 3985 days and 15 hours to each time then what you have will do it. You haven't explained what you are trying to do to the data or what you expect the final result to be exactly. – richard_ Jun 12 '19 at 13:18
  • Does this help? https://stackoverflow.com/questions/765797/python-timedelta-in-years – souldeux Jun 12 '19 at 13:30
  • Maybe my assumption in the question was wrong. From a quick check, it is likely that pd.Timedelta adjusts the number of days in Februaries automatically according to the year. I will check for more detail. – k.ko3n Jun 12 '19 at 13:35

0 Answers0