What is Timestamp.astimezone() in pandas?
Overview
Timestamp.astimezone() from the pandas software library is used to convert the timezone-aware Timestamp into another time zone.
Syntax
Timestamp.astimezone(tz)
Syntax for Timestamp.astimezone()
import pandas as pdts = pd.Timestamp('2021-02-10 01:15:52.192348551+0800', tz='UTC')print(ts)ts.astimezone('Europe/Berlin')print(ts)
import pandas as pdts= pd.Timestamp(year = 2022, month = 1, day = 31,hour = 12, minute = 49, tz = 'Asia/Tokyo')# Convert to Tokyo time zone:ts.astimezone(tz='US/Central')print(ts)
Line 2: We create
Timestamp()instance, withyear,month,day,hour,minuteand time zoneUTCas an additional argument.Line 5: We change the time zone to
US/Central.