Categories
Python Answers

How to convert Python Pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone?

Spread the love

To convert Python Pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone, we call tz_localize.

For instance, we write

pd.Timestamp('2019-10-07 10:30:19.428748+0200', tz='Europe/Brussels')

to convert the timestamp with the tz argument set to the timezone we want to convert to.

We can call tz_localize to convert the timezone to naive local time

pd.Timestamp.now(tz='Europe/Brussels').tz_localize(None)

And we can call tz_convert with None to convert the timestamp with a given time zone to UTC with

pd.Timestamp.now(tz='Europe/Brussels').tz_convert(None) 

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *