![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements