title: calculate descriptive statistics in pandas dataframe based on a condition cyclically
body: <p>I have a pandas DataFrame with more than 100 thousands of rows. Index represents the time and two columns represents the sensor data and the condition.
  When the condition becomes 1, I want to start calculating score card (average and standard deviation) till the next 1 comes. This needs to be calculated for the whole dataset.</p>
  <p>Here is a picture of the DataFrame for a specific time span:</p>
  <p><a href="https://i.stack.imgur.com/7yO7d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7yO7d.png" alt="enter image description here" /></a></p>
  <p>What I thought is to iterate through index and items of the df and when condition is met I start to calculate the descriptive statistics.</p>
  <pre><code>cycle = 0
  
  for i, row in df_b.iterrows():
  if row['condition'] == 1:
      print('Condition is changed')
      cycle += 1
      print('cycle: ', cycle)
      #start = ?
      #end = ?
      #df_b.loc[start:end]
  </code></pre>
  <p>I am not sure how to calculate <code>start</code> and <code>end</code> for this DataFrame. The <code>end</code> will be the <code>start</code> for the next cycle. Additionally, I think this iteration is not the optimal one because it takes a bit of long time to iterate. I appreciate any idea or solution for this problem.</p>