我在跑Pandas 1.50
下面,我为2个不同的时间戳运行相同的代码,并得到2个不同的答案.
def test(now):
now = pd.Timestamp(now)
floored = now.floor(pd.Timedelta("48 hours"))
diff = now - floored
print(f"{now}, {interval}, {floored}, {diff}")
test('2023-10-18 23:59:03.793642')
test('2023-10-11 23:59:03.793642')
在test
函数中,我将时间戳固定为48小时间隔,然后计算原始时间戳和固定时间戳之间的时间增量差.
The first timestamp floors to midnight on the same day (so to a 24 hour interval).
The second timestamp floors to midnight on the previousday (so to a 48 hour interval - as requested).
Output:个
2023-10-18 23:59:03.793642, 48 hours, 2023-10-18 00:00:00, 0 days 23:59:03.793642 2023-10-11 23:59:03.793642, 48 hours, 2023-10-10 00:00:00, 1 days 23:59:03.793642
这是怎么回事?
为什么我会得到不同的结果?