title: Pandas group by consecutive numbers
body: <p>I'm dealing with a DataFrame like this:</p>
  
  <pre><code>n_days    probability
   0            0.01
   17           0.1
   18           0.11
   19           0.12
   40           0.2
   41           0.21
  </code></pre>
  
  <p>I want to group consecutive numbers and get the mean probability of each group, like this:</p>
  
  <pre><code>n_days     mean_probability
    0           0.01
   17-19        0.11
   40-41        0.205
  </code></pre>
  
  <p>Formatting on the <code>n_days</code> isn't too relevant.</p>
  
  <p>I tried something like:</p>
  
  <pre><code>df['diff_days'] = df.n_days - df.n_days.shift()
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>df.diff_days.eq(1)
  </code></pre>
  
  <p>Which brings this boolean:</p>
  
  <pre><code>n_days    probability   bool_eq
   0            0.01       False
   17           0.1        False
   18           0.11       True
   19           0.12       True       
   40           0.2        False
   41           0.21       True
  </code></pre>
  
  <p>Which seems to be a step forward, but I'm not sure how to follow up. Each <code>False</code> would be the start of each group, but how would I catch the whole group?
  Any help would be appreciated. Thanks.</p>