
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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
- Related Articles
- Python Pandas - Convert Timestamp to another time zone
- Python Pandas - Construct a naive UTC datetime from a POSIX timestamp
- Python Pandas - Convert given Timestamp to Period
- Python Pandas - Convert PeriodIndex object to Timestamp
- Python program to convert local time into GMT
- Python Pandas - Convert given Timestamp to Period with minutely frequency
- Python Pandas - Convert given Timestamp to Period with weekly frequency
- Python Pandas - Convert given Timestamp to Period with monthly frequency
- Python Pandas - Convert given Timestamp to Period with quarterly frequency
- Python Pandas - Convert given Timestamp to Period with hourly frequency
- Pandas - Convert a Timestamp object to a native Python datetime object
- Python Pandas - Convert PeriodIndex object to Timestamp and set the frequency
- Python Pandas - Get the current date and time from Timestamp object
- Python Pandas - Return a new Timestamp representing UTC day and time
- Comparing Timestamp in Python – Pandas

Advertisements