Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonmd opened this issue Dec 16, 2020 · 0 comments
Open

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

jonmd opened this issue Dec 16, 2020 · 0 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@jonmd
Copy link
Contributor

jonmd commented Dec 16, 2020

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

@jonmd jonmd added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 16, 2020
@jonmd jonmd self-assigned this Dec 16, 2020
@jonmd jonmd changed the title Make helper for DataFrame-to-Excel for date-times with timezoneinfo Make helper for DataFrame-to-Excel for date-times with tzinfo Mar 24, 2021
@jonmd jonmd removed their assignment Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant