title: How to do groupby and find unique items of a column in PySpark
body: <p>I have a pySpark dataframe, I want to group by a column and then find unique items in another column for each group. </p>
  
  <p>In pandas I could do,</p>
  
  <pre><code>data.groupby(by=['A'])['B'].unique()
  </code></pre>
  
  <p>I want to do the same with my spark dataframe. I could find the distictCount of items in the group and count also, like this</p>
  
  <pre><code>(spark_df.groupby('A')
      .agg(
          fn.countDistinct(col('B'))
              .alias('unique_count_B'),
          fn.count(col('B'))
              .alias('count_B')
          )
      .show())
  </code></pre>
  
  <p>But I couldn't find some function to find unique items in the group. </p>
  
  <p>For clarifying more consider a sample dataframe,</p>
  
  <pre><code>df = spark.createDataFrame(
    [(1, "a"), (1, "b"), (1, "a"), (2, "c")],
    ["A", "B"])
  </code></pre>
  
  <p>I am expecting to get an output like this,</p>
  
  <pre><code>+---+----------+
  |  A|  unique_B|
  +---+----------+
  |  1|  [a, b]  |
  |  2|  [c]     |
  +---+----------+
  </code></pre>
  
  <p>How to do get the output as in pandas in pySpark.?</p>