title: Pyspark groupby and return the whole row
body: <p>I have the following dataframe named df:</p>
  
  <pre><code>name    score    data1    data2
  Name1   23       'a'      'b'
  Name2   2        'c'      'd'
  Name1   100      'b'      'f'
  Name3   5        'a'      'f'
  Name2   6        'e'      'g'
  Name3   500      'f'      'n' 
  </code></pre>
  
  <p>The desired result:</p>
  
  <p>Find max score for each name and return the associated data (data1 and data 2) as a dict:</p>
  
  <pre><code>grouped_df = df.groupby('name').agg({'score':'max'})
  </code></pre>
  
  <p>This produces:</p>
  
  <pre><code>name   score 
  Name1  100
  Name2  6
  Name3  500
  </code></pre>
  
  <p>But what I would ideally like to get is</p>
  
  <pre><code>name   score  data1  data2
  Name1  100    'b'    'f'
  Name2  6      'e'    'g'
  Name3  500    'f'    'n'
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>dict = {'b':1, 'e':1,'f':2,'g':1}
  </code></pre>
  
  <p>I attempted joining df and grouped_df by 2 columns (name and score), but that doesn't keep only the max, it returns all the columns. Is there any acceptable solution for this using dataframes? </p>