title: Retrieve top n in each group of a DataFrame in pyspark
body: <p>There's a DataFrame in pyspark with data as below:</p>
  
  <pre><code>user_id object_id score
  user_1  object_1  3
  user_1  object_1  1
  user_1  object_2  2
  user_2  object_1  5
  user_2  object_2  2
  user_2  object_2  6
  </code></pre>
  
  <p>What I expect is returning 2 records in each group with the same user_id, which need to have the highest score. Consequently, the result should look as the following:</p>
  
  <pre><code>user_id object_id score
  user_1  object_1  3
  user_1  object_2  2
  user_2  object_2  6
  user_2  object_1  5
  </code></pre>
  
  <p>I'm really new to pyspark, could anyone give me a code snippet or portal to the related documentation of this problem? Great thanks!</p>