Skip to content

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

@jonmd

Description

@jonmd

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] pandas-dev/pandas#28921
[1] https://stackoverflow.com/questions/49198068/how-to-remove-timezone-from-a-timestamp-column-in-a-pandas-dataframe

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions