title: Pandas Groupby return n smallest - return whole row and not just the indices?
body: <p>I have a data set like this:</p>
  <pre><code>query  hit  score1  score2
  group1  hit1  0.9  0.8
  group1  hit2  0.2  0.9
  group1  hit3  0.2  0.9
  group2  hit1  0.1  0.3
  group2  hit2  0.6  0.8
  group2  hit3  0.3  0.3
  group2  hit4  0.7  0.5
  </code></pre>
  <p>I want the output to return the lowest n (e.g. 2) rows, per group, based on a columnn (e.g. score 1), so this would turn into:</p>
  <pre><code>query  hit  score1  score2
  group1  hit2  0.2  0.9
  group1  hit3  0.2  0.9
  group2  hit1  0.1  0.3
  group2  hit3  0.3  0.3
  </code></pre>
  <p>I wrote:</p>
  <pre><code>df = pd.read_csv('file_name.txt',sep='\t',header=0)
  df = df.groupby('query')['score1'].nsmallest(2).join(df,['score1'])
  print(df)
  </code></pre>
  <p>based on seeing <a href="https://stackoverflow.com/questions/43611780/pyspark-groupby-and-return-the-whole-row">this</a> answer.</p>
  <p>But I get the error <code>series has no attribute join</code>.</p>
  <p>I did this because when I run:</p>
  <pre><code>df = pd.read_csv('file_name.txt',sep='\t',header=0)
  df = df.groupby('query')['score1'].nsmallest(2)
  print(df)
  </code></pre>
  <p>but it only returns the column that the grouping is done by, I wasn't sure how to extend to return the whole row, hence why I tried based on a SO answer that gave me the error.</p>