I want to create a column “X“ where the values are cumulative sums of an original column “Y“. However, when a value in “X“ reaches a certain threshold (e.g., an absolute value less than 1,000), the cumulative calculation restarts from the next value in “Y“.
For example, given the original column "Y" with values [1100, 1100, -1300, -10000, 1000], how to get the desired result with values [1100, 2200, 900, -10000, -9000]?
You can first use the
cumsumfunction to cumulatively calculate the sum of the elements in "Y" and use theiiffunction to set the threshold. Here is an example script: