Để trả về thứ tự Gregorian sơ khai, hãy sử dụng timestamp.toordinal () phương pháp. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo đối tượng dấu thời gian trong Pandas
timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33)
Trả lại thứ tự Gregorian proleptic. Ví dụ:Ngày 1 tháng 1 của năm 1 là ngày 1
timestamp.toordinal()
Ví dụ
Sau đây là mã
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()) Đầu ra
Điều này sẽ tạo ra mã sau
Timestamp... 2021-09-18 11:50:20.000033 Gregorian ordinal... 738051