python - 什么决定了 Pandas 的最小和最大时间戳?

标签 python pandas datetime

Pandas 中的最小时间戳是:

pd.Timestamp.min
Timestamp('1677-09-21 00:12:43.145225')

最大值为:

pd.Timestamp.max
Timestamp('2262-04-11 23:47:16.854775807')

这意味着您无法将超出此范围的值转换为 Pandas 日期时间:

pd.Timestamp(datetime.date(2500, 1, 1))
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2500-01-01 00:00:00

什么决定了这些限制?

最佳答案

日期时间类型使用带符号的 64 位整数以纳秒为单位存储。 那么范围是 [2^-63;2^63 -1 ]。使用 0 作为 UNIX 纪元 (1970/01/01 00:00:00.0),通过运行此代码,您可以看到结果距离 0(unix 纪元)大约为 292 年。那么,最大值是以 0 开头,后跟 63 1

表示的日期

运行此代码来亲自证明这一点。

max_int=2**63-1 # maximum integer
max_int/=10**9 # from nanoseconds to seconds
max_int/=86400 # from seconds to days
max_int/=365 # from days to years (suppose no leap years)
print(1970+max_int) # print the maximum year, with an error of days

编辑:正如 Ben 在下面的评论中所写,我没有报告来源。 here

关于python - 什么决定了 Pandas 的最小和最大时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55323548/

相关文章:

python - 使用 beautifulsoup 仅从 html 页面中抓取以 .ece 结尾的超链接

python - 将 JSON 行导入 Pandas

c# 在不同的文化中转换日期时间

python - 保留 undefined variable

python - 为什么 int(float(str)) 工作但 int(str) 不工作

python - pandas 数据框的条件函数,if 与 else 更改值

pandas - Pyspark、Spark SQL 和 toPandas().shape 中计数不一致的原因是什么?

r - 从日期时间更改为数字并返回到 R 中的日期时间

sql - 仅将带有年份和月份的字符串...转换为仅限年份和月份的日期格式

python - 发送自动短信警报 Python/Django