หากต้องการคืนค่าลำดับเกรกอเรียนที่เป็นโรคประจำตัว ให้ใช้ timestamp.toordinal() กระบวนการ. ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
สร้างวัตถุประทับเวลาใน Pandas
timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33)
ส่งคืนลำดับเกรกอเรียนเป็นโรคประจำตัว ตัวอย่าง:วันที่ 1 มกราคม ของปี 1 เป็นวันที่ 1
timestamp.toordinal()
ตัวอย่าง
ต่อไปนี้เป็นรหัส
import pandas as pd
# set the timestamp object in Pandas
timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33)
# display the Timestamp
print("Timestamp...\n", timestamp)
# Return proleptic Gregorian ordinal.
# Example: January 1 of year 1 is day 1.
print("\nGregorian ordinal...\n", timestamp.toordinal()) ผลลัพธ์
ซึ่งจะได้รหัสดังต่อไปนี้
Timestamp... 2021-09-18 11:50:20.000033 Gregorian ordinal... 738051