แปลง Timestamp เป็นเขตเวลาอื่น ใช้ timestamp.tz_convert() . ตั้งค่าเขตเวลาเป็นพารามิเตอร์ ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
สร้างวัตถุประทับเวลาใน Pandas เราได้กำหนดเขตเวลาด้วย
timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')
แปลงเขตเวลาของการประทับเวลา
timestamp.tz_convert('Australia/Brisbane')) ตัวอย่าง
ต่อไปนี้เป็นรหัส
import pandas as pd
# set the timestamp object in Pandas
# we have also set the timezone
timestamp = pd.Timestamp('2021-10-14T15:12:34.261811624', tz='US/Eastern')
# display the Timestamp
print("Timestamp...\n", timestamp)
# convert timezone
print("\nConvert the Timestamp timezone...\n",
timestamp.tz_convert('Australia/Brisbane')) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Timestamp... 2021-10-14 15:12:34.261811624-04:00 Convert the Timestamp timezone... 2021-10-15 05:12:34.261811624+10:00