title: Sample dataframe by value in column and keep all rows
body: <p>I want to sample a Pandas dataframe using values in a certain column, but I want to keep all rows with values that are in the sample.</p>
  <p>For example, in the dataframe below I want to randomly sample some fraction of the values in <code>b</code>, but keep <strong>all</strong> corresponding rows in <code>a</code> and <code>c</code>.</p>
  <pre><code>d = pd.DataFrame({'a': range(1, 101, 1),'b': list(range(0, 100, 4))*4, 'c' :list(range(0, 100, 2))*2} )
  </code></pre>
  <p>Desired example output from a 16% sample:</p>
  <pre><code>Out[66]: 
       a   b   c
  0    1   0   0
  1   26   0  50
  2   51   0   0
  3   76   0  50
  4    4  12   6
  5   29  12  56
  6   54  12   6
  7   79  12  56
  8   18  68  34
  9   43  68  84
  10  68  68  34
  11  93  68  84
  12  19  72  36
  13  44  72  86
  14  69  72  36
  15  94  72  86
  
  </code></pre>
  <p>I've tried sampling the series and merging back to the main data, like this:</p>
  <pre><code>In [66]: pd.merge(d, d.b.sample(int(.16 * d.b.nunique())))
  </code></pre>
  <p>This creates the desired output, but it seems inefficient. My real dataset has millions of values in <code>b</code> and hundreds of millions of rows. I know I could also use some version of ``isin```, but that also is slow.</p>
  <p>Is there a more efficient way to do this?</p>