I have a dataframe that looks like this:
night DSWRF_integ
ForecastTime
2018-05-12 00:00:00 1.0 1
2018-05-12 00:15:00 0.0 1
2018-05-12 00:30:00 0.0 1
2018-05-12 00:45:00 0.0 1
2018-05-12 01:00:00 0.0 0
2018-05-12 01:15:00 0.0 0
2018-05-12 01:30:00 0.0 0
2018-05-12 01:45:00 0.0 0
2018-05-12 02:00:00 0.0 0
2018-05-12 02:15:00 0.0 0
2018-05-12 02:30:00 0.0 0
2018-05-12 02:45:00 0.0 0
2018-05-12 03:00:00 0.0 0
2018-05-12 03:15:00 0.0 0
2018-05-12 03:30:00 0.0 0
2018-05-12 03:45:00 0.0 0
2018-05-12 04:00:00 0.0 0
2018-05-12 04:15:00 0.0 0
2018-05-12 04:30:00 0.0 0
2018-05-12 04:45:00 0.0 0
2018-05-12 05:00:00 0.0 0
2018-05-12 05:15:00 0.0 0
2018-05-12 05:30:00 0.0 0
2018-05-12 05:45:00 0.0 0
2018-05-12 06:00:00 0.0 0
2018-05-12 06:15:00 0.0 0
2018-05-12 06:30:00 0.0 0
2018-05-12 06:45:00 0.0 0
2018-05-12 07:00:00 0.0 0
2018-05-12 07:15:00 0.0 0
2018-05-12 07:30:00 0.0 0
2018-05-12 07:45:00 0.0 0
2018-05-12 08:00:00 0.0 0
2018-05-12 08:15:00 0.0 0
2018-05-12 08:30:00 0.0 0
2018-05-12 08:45:00 0.0 0
2018-05-12 09:00:00 0.0 0
2018-05-12 09:15:00 0.0 0
2018-05-12 09:30:00 0.0 0
2018-05-12 09:45:00 0.0 0
2018-05-12 10:00:00 0.0 0
2018-05-12 10:15:00 0.0 0
2018-05-12 10:30:00 0.0 0
2018-05-12 10:45:00 0.0 0
2018-05-12 11:00:00 0.0 0
2018-05-12 11:15:00 0.0 1
2018-05-12 11:30:00 0.0 1
2018-05-12 11:45:00 0.0 1
2018-05-12 12:00:00 0.0 0
2018-05-12 12:15:00 0.0 0
2018-05-12 12:30:00 0.0 0
2018-05-12 12:45:00 0.0 0
2018-05-12 13:00:00 0.0 0
2018-05-12 13:15:00 0.0 0
2018-05-12 13:30:00 0.0 0
2018-05-12 13:45:00 0.0 0
2018-05-12 14:00:00 1.0 1
2018-05-12 14:15:00 1.0 1
2018-05-12 14:30:00 1.0 1
2018-05-12 14:45:00 1.0 1
2018-05-12 15:00:00 1.0 1
I am trying to figure out a logic, without iterating over the dataframe as it is too slow, to be able to convert consecutive zeros in the column DSWRF_integ to ones, only when the number of consecutive zeros is smaller than a specific threshold (for example threshold=10).
In this specific case, I would like to replace all the zeros in column DSWRF_integ, with ones, for the time period 2018-05-12 12:00:00 to 2018-05-12 13:45:00 , because the number of consecutive zeros there is smaller than 10.
The resulting dataframe should look like this:
night DSWRF_integ
ForecastTime
2018-05-12 00:00:00 1.0 1
2018-05-12 00:15:00 0.0 1
2018-05-12 00:30:00 0.0 1
2018-05-12 00:45:00 0.0 1
2018-05-12 01:00:00 0.0 0
2018-05-12 01:15:00 0.0 0
2018-05-12 01:30:00 0.0 0
2018-05-12 01:45:00 0.0 0
2018-05-12 02:00:00 0.0 0
2018-05-12 02:15:00 0.0 0
2018-05-12 02:30:00 0.0 0
2018-05-12 02:45:00 0.0 0
2018-05-12 03:00:00 0.0 0
2018-05-12 03:15:00 0.0 0
2018-05-12 03:30:00 0.0 0
2018-05-12 03:45:00 0.0 0
2018-05-12 04:00:00 0.0 0
2018-05-12 04:15:00 0.0 0
2018-05-12 04:30:00 0.0 0
2018-05-12 04:45:00 0.0 0
2018-05-12 05:00:00 0.0 0
2018-05-12 05:15:00 0.0 0
2018-05-12 05:30:00 0.0 0
2018-05-12 05:45:00 0.0 0
2018-05-12 06:00:00 0.0 0
2018-05-12 06:15:00 0.0 0
2018-05-12 06:30:00 0.0 0
2018-05-12 06:45:00 0.0 0
2018-05-12 07:00:00 0.0 0
2018-05-12 07:15:00 0.0 0
2018-05-12 07:30:00 0.0 0
2018-05-12 07:45:00 0.0 0
2018-05-12 08:00:00 0.0 0
2018-05-12 08:15:00 0.0 0
2018-05-12 08:30:00 0.0 0
2018-05-12 08:45:00 0.0 0
2018-05-12 09:00:00 0.0 0
2018-05-12 09:15:00 0.0 0
2018-05-12 09:30:00 0.0 0
2018-05-12 09:45:00 0.0 0
2018-05-12 10:00:00 0.0 0
2018-05-12 10:15:00 0.0 0
2018-05-12 10:30:00 0.0 0
2018-05-12 10:45:00 0.0 0
2018-05-12 11:00:00 0.0 0
2018-05-12 11:15:00 0.0 1
2018-05-12 11:30:00 0.0 1
2018-05-12 11:45:00 0.0 1
2018-05-12 12:00:00 0.0 1
2018-05-12 12:15:00 0.0 1
2018-05-12 12:30:00 0.0 1
2018-05-12 12:45:00 0.0 1
2018-05-12 13:00:00 0.0 1
2018-05-12 13:15:00 0.0 1
2018-05-12 13:30:00 0.0 1
2018-05-12 13:45:00 0.0 1
2018-05-12 14:00:00 1.0 1
2018-05-12 14:15:00 1.0 1
2018-05-12 14:30:00 1.0 1
2018-05-12 14:45:00 1.0 1
2018-05-12 15:00:00 1.0 1
I have tried various approaches, using auxilliary columns but none of them has produced anything close to what I want. Any help would be highly appreciated :)