title: pandas operation by group
body: <p>I have a dataframe like this</p>
  <pre><code>df = pd.DataFrame({'id': [205,205,205, 211, 211, 211]
                    , 'date': pd.to_datetime(['2019-12-01','2020-01-01', '2020-02-01'
                                             ,'2019-12-01' ,'2020-01-01', '2020-03-01'])})
  df
  
      id  date
  0   205 2019-12-01
  1   205 2020-01-01
  2   205 2020-02-01
  3   211 2019-12-01
  4   211 2020-01-01
  5   211 2020-03-01
  </code></pre>
  <p>where the column <code>date</code> is made by consecutive months for <code>id 205</code> but not for <code>id 211</code>.</p>
  <p><strong>I want to keep only the observations (<code>id</code>) for which I have monthly data without jumps.</strong> In this example I want:</p>
  <pre><code>    id  date
  0   205 2019-12-01
  1   205 2020-01-01
  2   205 2020-02-01
  </code></pre>
  <p>Here I am collecting the <code>id</code> to keep:</p>
  <pre><code>keep_id = []
  for num in pd.unique(df.index):
      temp = (df.loc[df['id']==num,'date'].dt.year - df.loc[df['id']==num,'date'].shift(1).dt.year) * 12 + df.loc[df['id']==num,'date'].dt.month - df.loc[df['id']==num,'date'].shift(1).dt.month
      temp.values[0] = 1.0 # here I correct the first entry
      if (temp==1.).all():
          keep_id.append(num)
  </code></pre>
  <p>where I am using <code>(df.loc[num,'date'].dt.year - df.loc[num,'date'].shift(1).dt.year) * 12 + df.loc[num,'date'].dt.month - df.loc[num,'date'].shift(1).dt.month</code> to compute the difference in months from the previous <code>date</code> for every <code>id</code>.</p>
  <p>This seems to work when tested on a small portion of <code>df</code>, but I'm sure there is a better way of doing this, maybe using the <code>.groupby()</code> method.</p>
  <p><strong>Since <code>df</code> is made of millions of observations my code takes too much time (and I'd like to learn a more efficient and pythonic way of doing this)</strong></p>