Python Pandas - 返回预期的公历序数
pythonserver side programmingprogrammingpandas更新于 2025/12/28 9:16:17
要返回预期的公历序数,请使用 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("\nGregorian ordinal...\n", timestamp.toordinal())
输出
这将生成以下代码
时间戳... 2021-09-18 11:50:20.000033 Gregorian ordinal... 738051
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

