eq-python-client icon indicating copy to clipboard operation
eq-python-client copied to clipboard

Make helper for DataFrame-to-Excel for date-times with tzinfo

Open jonmd opened this issue 5 years ago • 0 comments

Rationale

pandas/io/formats/excel.py complains that Excel does not support time-zones with invoking df.to_excel() on a dataframe with timezone-aware date-times.

The documentation tells you options={'remove_timezone': True} to the ExcelWriter initiation, but this behaviour was changed in pandas v0.25. It doesn't seem like the pandas developers will fix it [0].

How to fix it?

So, the workaround (I believe) would be to remove time zones from the date-times before converting to Excel.

I found a StackOverflow post answering this [1]. However the proposed solution didn't work, so I rewrote the code to do basically the same thing:

df.index = df.index.map(lambda d: d.replace(tzinfo=None))

This example mutates the original data frame. However, with this as a starting point, figure out how to incorporate an helper in the client.


[0] https://github.com/pandas-dev/pandas/issues/28921 [1] https://stackoverflow.com/questions/49198068/how-to-remove-timezone-from-a-timestamp-column-in-a-pandas-dataframe

jonmd avatar Dec 16 '20 15:12 jonmd