title: Filterning top n row based on groupby condition
body: <p>I have a dataframe which have 4 column User_id,Transaction_id,product and datetime. For each user i have to select his top n recent transaction,Let assume n=2, My dataframe is like:</p>
  
  <pre><code>    transaction_id  user_id  product  date
           T1             U1     P1     2019-03-27
           T1             U1     P2     2019-03-27
           T1             U1     P3     2019-03-27
           T2             U1     P2     2019-03-21
           T2             U1     P3     2019-03-21
           T3             U1     P2     2019-03-20
  </code></pre>
  
  <p>I tried to do it by taking help of this <a href="https://stackoverflow.com/questions/41525911/group-by-pandas-dataframe-and-select-latest-in-each-group">group by pandas dataframe and select latest in each group</a> </p>
  
  <p>What i am expecting as a output is:</p>
  
  <pre><code>   transaction_id   user_id  product  date
          T1            U1       P1     2019-03-27
          T1            U1       P2     2019-03-27
          T1            U1       P3     2019-03-27
          T2            U1       P2     2019-03-21
          T2            U1       P3     2019-03-21
  </code></pre>