title: Get top N values in an inner level in a MultiIndex based dataframe
body: <p>I have a Pandas MultiIndex DataFrame that was converted from a xarray Dataset with 3 dimensions being time, latitude and longitude and two variables &quot;FFDI&quot; and &quot;REF_ID&quot;). Time = 17696, daily from 1972-01-20 to 2020-06-30) and latitude (=148) and longitude (=244)</p>
  <p>The dataframe looks like:</p>
  <pre><code>                                    FFDI    REF_ID
  latitude    longitude   time        
  -39.200001  140.800003  2009-02-07  10.2    0
                          2009-01-30  10.1    0
                          1983-02-12  10.0    0
                          2003-01-13  9.8     0
                          2019-12-28  9.8     0
                          2000-01-17  9.7     0
              ...     ...     ...     ...     ...
  
  -33.900002  150.000000  ... ...     ...     ...
                          1994-06-16  0.9     36111
                          1978-07-07  0.2     36111
                          2020-08-28  0.1     36111
                          2007-06-09  0.0     36111
                          1994-07-30  0.0     36111
                          1987-06-21  0.0     36111
                          
  639037952 rows × 2 columns
  </code></pre>
  <p>The DataFrame has already been sorted descending on &quot;FFDI&quot;. What I want to achieve is get top N (say 3) &quot;time&quot; rows for each latitude and longitude.</p>
  <p>So the DataFrame will look like if N = 3:</p>
  <pre><code>                                    FFDI    REF_ID
  latitude    longitude   time        
  -39.200001  140.800003  2009-02-07  10.2    0
                          2009-01-30  10.1    0
                          1983-02-12  10.0    0
  -39.200001  140.83786   2001-01-03  10.5    0
                          2006-01-18  10.3    0
                          2009-02-07  10.2    0
              ...     ...     ...     ...     ...
  
  -33.900002  150.000000  2009-02-07  10.9    36111
                          2006-01-10  10.7    36111
                          1983-01-23  10.6    36111
  </code></pre>