df
| index | y position | result |
|---|---|---|
| 0 | 1 | |
| 1 | 2 | |
| 2 | 3 | |
| 3 | 2 | |
| 4 | 1 | |
| 5 | 0 | 3 |
| 6 | 2 | |
| 7 | 3 | |
| 8 | 2 | 1 |
| 9 | 5 | |
| 10 | 0 | 5 |
| 11 | 0 | * |
* = Special value to be filled later
I'm calculating the total distance taken only when its y coordinate values drop. When it's decreasing subsequently, I only take the last index that has all the previous (continued) distance summed up (as shown in the column desired result).
If the distances are the same subsequently, then I would like to put in some unique value so that I can replace all of them later with one value.
There are millions of rows to go through so for loop will take too long. Is there be a faster way without using a for loop?