So I have a dataframe of daily weather data and if the temp is above 0. e.g:
|date|temp|pos_temp|
I am trying to make a column that has a cumulative sum for days in a row with temperatures above zero. I made a one-hot encoded column with a 1 or 0 for days above 0, but I'm having trouble counting the cumulative days with a '1' in the 'positive' column.
example
date |temp|pos_temp|
2020-04-27|1 |1 |
2020-04-28|-1 |0 |
2020-04-29|-2 |0 |
2020-04-30|4 |1 |
2020-05-01|7 |1 |
2020-05-02|10 |1 |
2020-05-03|14 |1 |
2020-05-04|13 |1 |
I'm trying to make a column like this:
date |temp|pos_temp|cum_above_0
2020-04-27|1 |1 |nan
2020-04-28|-1 |0 |0
2020-04-29|-2 |0 |0
2020-04-30|4 |1 |1
2020-05-01|7 |1 |2
2020-05-02|10 |1 |3
2020-05-03|14 |1 |4
2020-05-04|13 |1 |5