title: pyspark equivalent of pandas groupby + apply on column
body: <p>I have a spark DataFrame and I would like to count the number of unique values for a variable after groupby. </p>
  
  <p>In pandas I can obtain it as : <code>df.groupby('UserName').apply(lambda x: x['Server'].nunique())</code></p>
  
  <p>How can I get the same results when <code>df</code> is a pyspark dataframe? </p>