ในการแปลงอ็อบเจ็กต์ Timestamp เป็นอ็อบเจ็กต์ Python datetime ดั้งเดิม ให้ใช้เมธอด timestamp.to_pydatetime()
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
สร้างวัตถุประทับเวลาใน Pandas
timestamp = pd.Timestamp('2021-09-11T13:12:34.261811')
แปลงการประทับเวลาเป็นอ็อบเจ็กต์วันที่และเวลา Python ดั้งเดิม
timestamp.to_pydatetime()
ตัวอย่าง
ต่อไปนี้เป็นรหัส
import pandas as pd
# set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-11T13:12:34.261811')
# display the Timestamp
print("Timestamp...\n", timestamp)
# convert timestamp to native Python datetime object
print("\nConvert Timestamp...\n", timestamp.to_pydatetime()) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Timestamp... 2021-09-11 13:12:34.261811 Convert Timestamp... 2021-09-11 13:12:34.261811