title: Pyspark --- adding new column with values per group by
body: <p>Suppose I have the following data set: </p>
  
  <pre><code>a | b   
  1 | 0.4 
  1 | 0.8 
  1 | 0.5 
  2 | 0.4
  2 | 0.1
  </code></pre>
  
  <p>I would like to add a new column called "label" where the values are determined locally for each group of values in <strong>a</strong>. The highest value of <strong>b</strong> in a group <strong>a</strong> is labeled 1 and all others are labeled 0.</p>
  
  <p>The output would look like this : </p>
  
  <pre><code>a | b   | label
  1 | 0.4 | 0
  1 | 0.8 | 1
  1 | 0.5 | 0
  2 | 0.4 | 1
  2 | 0.1 | 0
  </code></pre>
  
  <p>How can I do this efficiently using PySpark?</p>