title: Get the first (or last) row of a grouped PySpark Data frame
body: <p>The data is simply a collection of ids and their login date like this: </p>
  
  <pre><code>data = pd.DataFrame({'id': ['a', 'b', 'c', 'b', 'c'], 
                     'date': ['2017/12/10', '2017/12/10', '2017/12/11', '2017/12/12', '2017/12/12']})
  
  id | date
  ---------------
   a | 2017/12/10
   b | 2017/12/10
   c | 2017/12/11
   b | 2017/12/12
   c | 2017/12/12
  </code></pre>
  
  <p>Each id may have multiple records. With Pandas, if I want to single-out only the most recent record of each id, I would do this:</p>
  
  <pre><code>most_recent = data.sort_values('date', ascending=False).groupby('id').head(1)
  </code></pre>
  
  <p>How do I achieve the same thing with a PySpark Dataframe? </p>
  
  <p>I've tried something like this:</p>
  
  <pre><code>data.orderBy(data.date, ascending=False).groupBy('id')
  </code></pre>
  
  <p>But because I don't need to use any aggregation function after this, I am stuck.</p>
  
  <p>I realize I could turn PySpark dataframe to a Pandas dataframe, but I would like to know how to do it with PySpark.</p>