Skip to content
Advertisement

How to remove timezone from a Timestamp column in a pandas dataframe

I read Pandas change timezone for forex DataFrame but I’d like to make the time column of my dataframe timezone naive for interoperability with an sqlite3 database.

The data in my pandas dataframe is already converted to UTC data, but I do not want to have to maintain this UTC timezone information in the database.

Given a sample of the data derived from other sources, it looks like this:

JavaScript

gives:

JavaScript

but

JavaScript

gives an eventual error:

JavaScript

What do I do to replace the column with a timezone naive timestamp?

Advertisement

Answer

The column must be a datetime dtype, for example after using pd.to_datetime. Then, you can use tz_localize to change the time zone, a naive timestamp corresponds to time zone None:

JavaScript

Unless the column is an index (DatetimeIndex), the .dt accessor must be used to access pandas datetime functions.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement