title: return the n largest/smallest values in pandas dataframe where many rows contain same values
body: <p>I am wondering how to return the rows containing n smallest values in a dataframe df that looks like this.</p>
  
  <pre><code>id           xx             count
  1            A              1
  2            B              1
  3            C              3
  4            D              2
  5            E              3
  6            F              10
  7            G              11
  8            H              17
  </code></pre>
  
  <p>Say I want to find the rows containing the 3 smallest counts (in this case, the 3 smallest counts are 1,2 and 3). So, I want the answer to be like this:</p>
  
  <pre><code>id           xx             count
      1            A              1
      2            B              1
      4            D              2
      3            C              3
      5            E              3
  </code></pre>
  
  <p>If I simply sort the dataframe based on count and use <code>df.nsmallest(3, 'count')</code>, it would only return the first three rows of the desired dataframe. But I want all rows that contain the 3 smallest counts. Is there any simpler way to do this in pandas? Thanks in advance!</p>