我有一个带有 timedeltas 的 pandas DataFrame 作为单独列中这些增量的累积总和,以毫秒为单位。下面提供了一个示例:
Transaction_ID Time TimeDelta CumSum[ms]
1 00:00:04.500 00:00:00.000 000
2 00:00:04.600 00:00:00.100 100
3 00:00:04.762 00:00:00.162 262
4 00:00:05.543 00:00:00.781 1043
5 00:00:09.567 00:00:04.024 5067
6 00:00:10.654 00:00:01.087 6154
7 00:00:14.300 00:00:03.646 9800
8 00:00:14.532 00:00:00.232 10032
9 00:00:16.500 00:00:01.968 12000
10 00:00:17.543 00:00:01.043 13043
我希望能够为 CumSum[ms] 提供最大值,之后累积和将从 0 重新开始。例如,如果在上面的示例中最大值为 3000,则结果将如下所示:
Transaction_ID Time TimeDelta CumSum[ms]
1 00:00:04.500 00:00:00.000 000
2 00:00:04.600 00:00:00.100 100
3 00:00:04.762 00:00:00.162 262
4 00:00:05.543 00:00:00.781 1043
5 00:00:09.567 00:00:04.024 0
6 00:00:10.654 00:00:01.087 1087
7 00:00:14.300 00:00:03.646 0
8 00:00:14.532 00:00:00.232 232
9 00:00:16.500 00:00:01.968 2200
10 00:00:17.543 00:00:01.043 0
我已经探索过使用模运算符,但只有当结果 cumsum 等于提供的限制时(即 500 % 500 的 cumsum[ms] 等于零),我才成功地重置为零。
提前感谢您的任何想法,如果我可以提供更多信息,请告诉我。