Python Pandas - 返回前攝格里高利曆序數


若要返回前攝格里高利曆序數,請使用 timestamp.toordinal() 方法。首先,匯入所需的庫 −

import pandas as pd

在 Pandas 中建立時間戳物件

timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33)

返回前攝格里高利曆序數。示例:年份 1 的 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

更新於: 13-10-2021

216 瀏覽

開啟您的 職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.