I find it difficult to work with time / time zones. I have form JSON source data
{ "Date": "28 Sep 2009 00:00:00", .... }
This data is then loaded into MongoDB, and this string representation of the date is converted to a JavaScript Date object. This conversion to UTC results in the following date
{ "_id": ObjectId("577a788f4439e17afd4e21f7"), "Date": ISODate("2009-09-27T23:00:00Z") }
It “looks” as if the date had really been moved forward to the day, I suppose (possibly wrong) that this is due to the fact that my car is set to Irish standard time .
Then I read this data from MongoDB and used it to create pandas DatetimeIndex
idx = pd.DatetimeIndex([x['Date'] for x in test_docs], freq='D')
which gives me

which is incorrect, since the time was not correctly converted from UTC to local time. So I implemented the solution given in this answer
idx = pd.DatetimeIndex([x['Date'] for x in test_docs], freq='D') idx = idx.tz_localize(tz=tz.tzutc()) idx = idx.tz_convert(tz=tz.tzlocal()) frame = DataFrame(test_docs, index=idx) frame = frame.drop('Date', 1)
which gives me the right day ago

Then I normalize DatetimeIndex, so the clock is deleted, which allows me to group all the records per day.
frame.groupby(idx).sum()
At this point, however, something strange is happening. Dates are ultimately grouped as follows

but this does not reflect the dates in the frame

Can anyone shed some light on where I can go wrong?
Reply to @ptrj
Explicitly use my timezone as a string
idx = pd.DatetimeIndex([x['Date'] for x in test_docs], freq='D') idx = idx.tz_localize(tz=tz.tzutc()) idx = idx.tz_convert(tz='Europe/Dublin') idx = idx.normalize() frame = DataFrame(test_docs, index=idx) ... ... aggregate = frame.groupby(idx).sum() aggregate.plot()
this does not work for me, it leads to the following schedule

For some reason, groupby is not grouping correctly in 2014, as shown below.

If instead I use
idx = idx.tz_convert(tz.gettz('Europe/Dublin'))
I get the same problem
Convert to Object
idx = pd.DatetimeIndex([x['Date'] for x in test_docs], freq='D') idx = idx.tz_localize(tz=tz.tzutc()) idx = idx.tz_convert(tz=tz.tzlocal()) idx = idx.normalize() frame = DataFrame(test_docs, index=idx) aggregate = frame.groupby(idx.astype(object)).sum()
This approach works right for me
