title: Randomly Sample Pyspark dataframe with column conditions
body: <p>I'm trying to randomly sample a Pyspark dataframe where a column value meets a certain condition. I would like to use the <code>sample</code> method to randomly select rows based on a column value. Let's say I have the following data frame:</p>
  
  <pre><code>+---+----+------+-------------+------+
  | id|code|   amt|flag_outliers|result|
  +---+----+------+-------------+------+
  |  1|   a|  10.9|            0|   0.0|
  |  2|   b|  20.7|            0|   0.0|
  |  3|   c|  30.4|            0|   1.0|
  |  4|   d| 40.98|            0|   1.0|
  |  5|   e| 50.21|            0|   2.0|
  |  6|   f|  60.7|            0|   2.0|
  |  7|   g|  70.8|            0|   2.0|
  |  8|   h| 80.43|            0|   3.0|
  |  9|   i| 90.12|            0|   3.0|
  | 10|   j|100.65|            0|   3.0|
  +---+----+------+-------------+------+
  </code></pre>
  
  <p>I would like to sample only 1(or any certain amount) of each of the <code>0, 1, 2, 3</code> based on the <code>result</code> column so I'd end up with this:</p>
  
  <pre><code>+---+----+------+-------------+------+
  | id|code|   amt|flag_outliers|result|
  +---+----+------+-------------+------+
  |  1|   a|  10.9|            0|   0.0|
  |  3|   c|  30.4|            0|   1.0|
  |  5|   e| 50.21|            0|   2.0|
  |  8|   h| 80.43|            0|   3.0|
  +---+----+------+-------------+------+
  
  </code></pre>
  
  <p>Is there a good programmatic way to achieve this, i.e take the same number of rows for each of the values given in a certain column? Any help is really appreciated!</p>