title: Pandas: flag consecutive values
body: <p>I have a pandas series of the form <code>[0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0 , 0 , 1].</code></p>
  
  <pre><code>0: indicates economic increase.
  1: indicates economic decline.
  </code></pre>
  
  <p>A recession is signaled by two consecutive declines (1).</p>
  
  <p>The end of the recession is signaled by two consecutive increase (0).</p>
  
  <p>In the above dataset I have two recessions, begin at index 3, end at index 5 and begin at index 8 end at index 11.</p>
  
  <p>I am at a lost for how to approach this with pandas.  I would like to identify the index for the start and end of the recession.  Any assistance would be appreciated.</p>
  
  <p>Here is my python attempt at a soln.</p>
  
  <pre><code>np_decline =  np.array([0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0 , 0 , 1])
  recession_start_flag = 0
  recession_end_flag = 0
  recession_start = []
  recession_end = []
  
  for i in range(len(np_decline) - 1):
      if recession_start_flag == 0 and np_decline[i] == 1 and np_decline[i + 1] == 1:
          recession_start.append(i)
          recession_start_flag = 1
      if recession_start_flag == 1 and np_decline[i] == 0 and np_decline[i + 1] == 0:
          recession_end.append(i - 1)
          recession_start_flag = 0
  
  print(recession_start)
  print(recession_end)
  </code></pre>
  
  <p>Is the a more pandas centric approach?
  Leon </p>