Python Pandas - Convert naive Timestamp to local time zone



To convert naive Timestamp to local time zone, use the timestamp.tz_locale(). Within that, set the timezone using the tz parameter.

At first, import the required libraries −

import pandas as pd

Creating a naive timestamp

timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') 

Add the timezone

timestamp.tz_localize(tz='Australia/Brisbane')

Example

Following is the code

 import pandas as pd # creating a naive timestamp timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624') # display the Timestamp print("Timestamp...\n", timestamp) # add a timezone print("\nTimestamp to local time zone...\n", timestamp.tz_localize(tz='Australia/Brisbane'))

Output

This will produce the following code

 Timestamp... 2021-09-14 15:12:34.261811624 Timestamp to local time zone... 2021-09-14 15:12:34.261811624+10:00
Updated on: 2021-10-13T07:16:57+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements