0

I have a list of occurrences (as decimal years from 0), some of which have an associated event, flagged as a 1 or 0, as columns of a pandas dataframe. This is for a situation where I am looking at the occurrence of severe storms in the past 10 years. If the storm is severe it is flagged as 1, if not severe it is flagged as 0.

I am interested in calculating the count of events in the prior N years from a given event, in the example below (worked up fairly painfully in Excel), this is 10 years. I am looking for a general solution that will allow me to vary the time window parameter, e.g. use 10, 5, 20 years. I have looked at recommended similar answers, but I think my problem is somewhat simpler and I am hoping for a simpler solution

+-----------------------------------+------------+-------------------------+
|             EventTime             |   Event    | Count previous 10 years |
+-----------------------------------+------------+-------------------------+
| 0                                 | 0          | 0                       |
| 1.068237534                       | 1          | 1                       |
| 1.838255342                       | 0          | 1                       |
| 2.773380548                       | 0          | 1                       |
| 2.808890959                       | 0          | 1                       |
| 3.690702466                       | 0          | 1                       |
| 9.739476712                       | 0          | 1                       |
| 10.77394795                       | 0          | 1                       |
| 12.19352575                       | 0          | 0                       |
| 13.20433753                       | 0          | 0                       |
| 17.12877178                       | 0          | 0                       |
| 19.04475205                       | 0          | 0                       |
| 20.84133616                       | 0          | 0                       |
| 24.77808603                       | 1          | 1                       |
| 25.84566548                       | 0          | 1                       |
| 28.67180137                       | 0          | 1                       |
| 29.92115671                       | 0          | 1                       |
| 29.96661096                       | 1          | 2                       |
| 31.06306027                       | 0          | 2                       |
| 32.87448904                       | 0          | 2                       |
| 34.06333781                       | 0          | 2                       |
| 34.13476411                       | 1          | 3                       |
| 34.79842082                       | 0          | 3                       |
| 35.70213288                       | 0          | 3                       |
+-----------------------------------+------------+-------------------------+
rbmales
  • 143
  • 1
  • 8
  • I do not believe that these problems are the same. I have unique times in each row, and only a single binary value (0 or 1) in the event column. This is not the case in the referenced solution. – rbmales Sep 26 '16 at 22:44
  • If anything, my problem appears to be closer to the solution in http://stackoverflow.com/questions/38726855/pandas-count-the-number-of-times-an-event-has-occurred-in-last-n-days-by-group but I have not been successful as yet in wrangling that solution into the format in which my data exists. – rbmales Sep 26 '16 at 22:49

0 Answers0