VOOZH about

URL: https://www.geeksforgeeks.org/pandas/python-pandas-timestamp-tz_localize/

โ‡ฑ Python | Pandas Timestamp.tz_localize - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | Pandas Timestamp.tz_localize

Last Updated : 9 Dec, 2021

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas Timestamp.tz_localize() function convert naive Timestamp to local time zone, or remove timezone from tz-aware Timestamp.

Syntax :Timestamp.tz_localize()
Parameters : 
tz : Time zone for time which Timestamp will be converted to. None will remove timezone holding local time. 
ambiguous : bool, โ€˜NaTโ€™, default โ€˜raiseโ€™ 
errors : โ€˜raiseโ€™, โ€˜coerceโ€™, default โ€˜raiseโ€™
Return : localized : Timestamp 
 

Example #1: Use Timestamp.tz_localize() function to convert a tz-aware Timestamp to a naive Timestamp object. 

Output : 

๐Ÿ‘ Image

Now we will use the Timestamp.tz_localize() function to convert the tz-aware Timestamp to naive Timestamp. 

Output : 

๐Ÿ‘ Image

As we can see in the output, the Timestamp.tz_localize() function has converted the given Timestamp to a naive Timestamp. 
  
Example #2: Use Timestamp.tz_localize() function to convert the given naive Timestamp to tz-aware Timestamp object. Set the timezone to 'US/Pacific'.

Output : 

๐Ÿ‘ Image

Now we will use the Timestamp.tz_localize() function to set the timezone of ts object to 'US/Pacific'. 

Output : 

๐Ÿ‘ Image

As we can see in the output, the Timestamp.tz_localize() function has set the timezone of the given object to 'US/Pacific'.
 

Comment

Explore