title: pandas, Find and keep consecutive rows - create a panel data
body: <p>I have a DataFrame like below:</p>
  
  <pre><code>df = {'time': [1999,2001,2002,2003,2007,1999,2000,2001,2003,2004],
        'id':['A','A','A','A','A','B','B','B','B','B'],
        'value':[0.1,0.1,0.1,0.1,0.6,0.2,0.2,0.2,0.2,0.2]}
  df = pd.DataFrame(df)
  </code></pre>
  
  <p>I want to create a panel dataset in the <code>id-time</code> level from it, which means, I want something like:</p>
  
  <pre><code>time id  value
  0  2001  A    0.1
  1  2002  A    0.1
  2  2003  A    0.6
  3  1999  B    0.2
  4  2000  B    0.2
  5  2001  B    0.2
  </code></pre>
  
  <p>Only consecutive rows of each <code>id</code> are left, I can finish this with just several lines in R, </p>
  
  <pre><code>df&lt;-df %&gt;% 
      mutate(time = as.integer(time)) %&gt;% 
      group_by(gvkey, grp = cumsum(c(1, diff(time) != 1))) %&gt;% 
      filter(n() &gt;= consec_obs)
  df&lt;-df[,setdiff(colnames(df),c('grp'))]
  </code></pre>
  
  <p>in which <code>consec_obs</code> is the minimum of consecutive rows one wants to keep.</p>
  
  <p>I searched for a while but couldn't find a solution, which surprised me a little bit as this is kind of basic econometric analysis manipulation, anyone knows how to do this with Python?</p>