I have a Pandas DataFrame representing a time series of scores. I want to use that score to calculate a CookiePoints column based on the following criteria:
- Every time the score improves compared to the previous score, a CookiePoint is given.
- Every time the score does not improve, all CookiePoints are taken away as punishment (CookiePoints is set to 0).
- 3 Cookiepoints can be traded in for a Cookie. Therefore, after 3 has been reached, the CookiePoints count should either be 1 (if score is higher) or 0 (if score isn't higher).
See below for an example:
Score CookiePoints
14 0
13 0
14 1
17 2
17 0
19 1
20 2
22 3
23 1
17 0
19 1
20 2
22 3
21 0
Note that this is a minimal, reproducible example. A solution must use a Pandas DataFrame, and ideally only vectorized operations.