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/