title: Extracting time series for best performing agents in a pandas DataFrame
body: <p>I apologise if this question is basic, but I've gone through the documentation and I am having trouble figuring out what the simple canonical way to deal with this problem is, although this is probably because I am very new to pandas.</p>
  
  <p>I have a DataFrame <code>df</code> representing time series data (where time is measured by <code>step</code>s) for <code>score</code>s of a series of systems, parametrised by hyperparameters <code>paramA</code> and <code>paramB</code>.</p>
  
  <p>A synthetic sample of the data is as follows:</p>
  
  <pre><code>| paramA | paramB | score | step |
  ----------------------------------
  |   A    |    c   |   .8  |  10  |
  |   B    |    e   |   .2  |  10  |
  |   A    |    f   |   .1  |  40  |
  |   C    |    c   |   .9  |  10  |
  |   B    |    e   |   .3  |  20  |
  |   B    |    c   |   .3  |  10  |
  |   A    |    c   |   .7  |  20  |
  |   C    |    f   |   .4  |  60  |
  |  ...   |   ...  |  ...  |  ... |
  </code></pre>
  
  <p>I want do the following things:</p>
  
  <h3>1. Find top scoring models</h3>
  
  <p>For each model (i.e. for each possible pair of hyperparameters in the dataset), find the row with the top score. I currently am doing this with:</p>
  
  <pre><code>df.groupby([df.paramA, df.paramB]).score.max()
  </code></pre>
  
  <h3>2. Extract time series for top scorers</h3>
  
  <p>I now want to get the time series for the top <code>k</code> models I obtained maxima for in the previous step.</p>
  
  <p>Obviously I can manually look up the top scoring models in the previous step, get <code>k</code> dataframes using <code>k</code> separate queries, but this feels slow and inelegant. I'm assuming there's a smarter way of doing this.</p>
  
  <p>Again, apologies if this is very simple, but any assistance in solving this problem the clever way, rather than the brute-force way I currently have in mind, will be appreciated.</p>