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
# 在 Pandas 中设置时间戳对象
timestamp = pd.Timestamp(2021, 9, 18, 11, 50, 20, 33)
# 显示时间戳
print("时间戳...\n", timestamp)
# 返回公历格里高利序数。
# 示例:1年1月1日为第1天。
print("\n公历格里高利序数...\n", timestamp.toordinal())
输出
这将产生以下代码
时间戳...
2021-09-18 11:50:20.000033
公历格里高利序数...
738051