gpt4 book ai didi

python - python中两个时间戳的平均值

转载 作者:太空狗 更新时间:2023-10-30 01:42:36 24 4
gpt4 key购买 nike

我有两个时间戳 (pandas.tslib.Timestamp) ts1ts2,我想计算它们的平均值。

(ts1+ts2)/2

但是,我收到了这个错误:

TypeError: unsupported operand type(s) for +: 'Timestamp' and 'Timestamp'

感谢您的帮助。

最佳答案

从另一个时间戳中减去一个时间戳会生成一个间隔,然后可以对其进行划分。

如错误所述,不允许添加时间戳。

解决方案涉及计算间隔,将间隔减半,然后将减半的间隔添加到较早的时间戳或从较晚的时间戳中减去。

from pandas.tslib import Timestamp
d1 = Timestamp.now()
# wait a few seconds
d2 = Timestamp.now()
d3 = d1 + (d2 - d1) / 2
# d3 will be the timestamp exactly in between d1 & d2

关于python - python中两个时间戳的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41723105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com