2

I noticed that if I have pandas datetime index inside a pandas dataframe, the value of the dates changes when I call them by using .value

Example.

import pandas as pd

date_try=pd.date_range(start='2017-01-01',end='2017-05-01',freq='MS')
date_df=pd.DataFrame(date_try)

print(date_df)

enter image description here

Now notice how the date values change when I call

print(date_df.values)

enter image description here

ayhan
  • 70,170
  • 20
  • 182
  • 203

1 Answers1

2

@DYZ is right, I run into this all the time setting up cronjobs on my aws box, where the time it's run doesn't correspond to what the source-file says is the time because it was produced in a different timezone You can try to re-index it in local time.

import pytz
eastern = pytz.timezone('US/Eastern')
df.index = index.tz_localize(pytz.utc).tz_convert(eastern)
Benloper
  • 448
  • 4
  • 13