![]() |
VOOZH | about |
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 :
๐ ImageNow we will use the Timestamp.tz_localize() function to convert the tz-aware Timestamp to naive Timestamp.
Output :
๐ ImageAs 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 :
๐ ImageNow we will use the Timestamp.tz_localize() function to set the timezone of ts object to 'US/Pacific'.
Output :
๐ ImageAs we can see in the output, the Timestamp.tz_localize() function has set the timezone of the given object to 'US/Pacific'.