title: Pandas: extract top three IDs based on values in a different column from a previous day
body: <p>I have a data frame like this:</p>
  
  <pre><code>date_test = pd.DataFrame({
      'id': ['q','w','e','r','t','y',
             'a','s','d','f','g',
             'z','x',
             'b','n','m','k'],
      'metric': [123,122,45,31,5,2,
                 634,372,312,229,110,
                 434,334,
                 256,156,44,23],
      'date':['2019-11-01','2019-11-01','2019-11-01','2019-11-01','2019-11-01', '2019-11-01', 
               '2019-11-02','2019-11-02','2019-11-02','2019-11-02','2019-11-02',
               '2019-11-04','2019-11-04',
              '2019-11-05','2019-11-05','2019-11-05','2019-11-05']
      })
  </code></pre>
  
  <p>It was sorted by <code>date</code> and <code>metric</code>. The tricky part is that I have gaps in dates, so I cannot calculate <code>previous</code> based on datestamp.
  For each date I need to grab top-3 <code>id</code>s. If there are fewer <code>id</code>s on a previous day, I should use <code>top_1</code> instead.
  The first date should be filled with NaNs as there is no previous period to look at.
  The result should look like this:</p>
  
  <pre><code>    id  metric  date        top_1   top_2   top_3
  0   q   123     2019-11-01  None    None    None
  1   w   122     2019-11-01  None    None    None
  2   e   45      2019-11-01  None    None    None
  3   r   31      2019-11-01  None    None    None
  4   t   5       2019-11-01  None    None    None
  5   y   2       2019-11-01  None    None    None
  6   a   634     2019-11-02  q       w       e
  7   s   372     2019-11-02  q       w       e
  8   d   312     2019-11-02  q       w       e
  9   f   229     2019-11-02  q       w       e
  10  g   110     2019-11-02  q       w       e
  11  z   434     2019-11-04  a       s       d
  12  x   334     2019-11-04  a       s       d
  13  b   256     2019-11-05  z       x       z
  14  n   156     2019-11-05  z       x       z
  15  m   44      2019-11-05  z       x       z
  16  k   23      2019-11-05  z       x       z
  </code></pre>
  
  <p>I will greatly appreciate your help!</p>