title: Getting top 3 values from multi-index pandas dataframe
body: <p>I have a multi-level grouped pandas dataframe which looks something like this:</p>
  
  <pre><code>date          AccountNum       ProgramName     Duration
  2017-11-12    12345            program1          200
                                 program2          300
                                 program4          100
                                 program5          250
                45678            program7          200
                                 program2          300
                                 program8          100
                                 program5          250
  
    .... more accounts for 2017-11-12
  
  2017-11-18    12345            program6          200
                                 program2          300
                                 program3          100
                                 program5          250 
                45678            program6          200
                                 program3          300
                                 program4          100
                                 program5          250
  etc-etc
  </code></pre>
  
  <p>The duration is aggregated already, it is an average by the date, by account number, and by program name. 
  Here was the code to get the dataframe above:</p>
  
  <pre><code>grouped = programs.groupby([pd.Grouper(freq='W'),'AccNum','ProgramName'])['Duration'].agg('mean')
  </code></pre>
  
  <p>The Duration column is the average per week for each account (and for each week).
  I need to select top 3 programs for each account per week.</p>
  
  <p>I tried nlargest() function but it does not seem to be working for me because I am either getting only 3 accounts back or losing the date column. Any help would be greatly appreciated.</p>
  
  <p>EDIT:
  Here is what I want the result to look like:</p>
  
  <pre><code>    date          AccountNum       ProgramName     Duration
      2017-11-12    12345            program2          300
                                     program5          250
                                     program1          200
                    45678            program2          300
                                     program5          259
                                     program7          200
  
        .... more accounts for 2017-11-12
  
      2017-11-18    12345            program2          300
                                     program5          250
                                     program6          200
                    45678            program3          300
                                     program5          250
                                     program6          200
   .... more dates and more accounts ..
  </code></pre>
  
  <p>Essentially, I need to keep the group structure -- by date/by account/top 3 programs based on duration. The end goal of this exercise is to be able to see the change in duration week after week for top 3 programs for each account. </p>