I have the following DataFrame, where Value refers to my observations, and Criterion indicates, when a Value should be set to np.nan.
| Value | Criterion |
|---|---|
| 3 | 0 |
| 3 | 0 |
| 5 | 1 |
| 7 | 0 |
| 2 | 0 |
| 2 | 0 |
| 8 | 1 |
| 8 | 0 |
| 8 | 0 |
| 1 | 0 |
Whenever Criterion is equal to 1, I want to set the Value in the same row, as well as all consecutive Values to zero until Value changes. The desired output should look like this.
| Value | Criterion |
|---|---|
| 3 | 0 |
| 3 | 0 |
| nan | 1 |
| 7 | 0 |
| 2 | 0 |
| 2 | 0 |
| nan | 1 |
| nan | 0 |
| nan | 0 |
| 1 | 0 |