I have a dataframe as show below:
index value
2003-01-01 00:00:00 14.5
2003-01-01 01:00:00 15.8
2003-01-01 02:00:00 0
2003-01-01 03:00:00 0
2003-01-01 04:00:00 13.6
2003-01-01 05:00:00 4.3
2003-01-01 06:00:00 13.7
2003-01-01 07:00:00 14.4
2003-01-01 08:00:00 0
2003-01-01 09:00:00 0
2003-01-01 10:00:00 0
2003-01-01 11:00:00 17.2
2003-01-01 12:00:00 0
2003-01-01 13:00:00 5.3
2003-01-01 14:00:00 0
2003-01-01 15:00:00 2.0
2003-01-01 16:00:00 4.0
2003-01-01 17:00:00 0
2003-01-01 18:00:00 0
2003-01-01 19:00:00 3.9
2003-01-01 20:00:00 7.2
2003-01-01 21:00:00 1.0
2003-01-01 22:00:00 1.0
2003-01-01 23:00:00 10.0
The index is datetime and have column record the rainfall value(unit:mm) in each hour,I would like to calculate the "Average wet spell duration", which means the average of continuous hours that exist values (not zero) in a day, so the calculation is
2 + 4 + 1 + 1 + 2 + 5 / 6 (events) = 2.5 (hr)
and the "average wet spell amount", which means the average of sum of the values in continuous hours in a day.
{ (14.5 + 15.8) + ( 13.6 + 4.3 + 13.7 + 14.4 ) + (17.2) + (5.3) + (2 + 4)+ (3.9 + 7.2 + 1 + 1 + 10) } / 6 (events) = 21.32 (mm)
The datafame above is just a example, the dataframe which I have have more longer time series (more than one year for example), how can I write a function so it could calculate the two value mentioned above in a better way? thanks in advance!
P.S. the values may be NaN, and I would like to just ignore it.