title: How to count the number of time intervals that meet a boolean condition within a pandas dataframe?
body: <p>I have a pandas <code>df</code> with a time series in <code>column1</code>, and a boolean condition in <code>column2</code>. This describes continuous time intervals that meet a specific condition. Note that the time intervals are of unequal length.</p>
  
  <pre><code>Timestamp   Boolean_condition
  1           1
  2           1
  3           0
  4           1
  5           1
  6           1
  7           0
  8           0
  9           1
  10          0
  </code></pre>
  
  <p><strong>How to count the total number of time intervals within the whole series that meet this condition?</strong> </p>
  
  <p>The desired output should look like this:</p>
  
  <pre><code>Timestamp   Boolean_condition   Event_number
  1           1                   1
  2           1                   1
  3           0                   NaN
  4           1                   2
  5           1                   2
  6           1                   2
  7           0                   NaN
  8           0                   NaN
  9           1                   3
  10          0                   NaN
  </code></pre>