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
广告