title: Scala - groupBy and count instances of each value
body: <p>I have a DataFrame DF and I want to count the number of each txn under the 2 Categories (Cat1 and Cat2).</p>
  
  <pre><code>DF                                
  +------------+-------+
  |  Category  |  txn  | 
  +-----===----+-------+  
  |  Cat1      |   A   |  
  |  Cat2      |   A   |
  |  Cat1      |   B   |
  |  Cat1      |   C   |
  |  Cat2      |   D   |
  |  Cat1      |   D   |
  |  Cat2      |   C   |
  |  Cat1      |   D   |
  |  Cat1      |   A   |
  |  Cat2      |   C   |
  |  Cat1      |   D   |
  |  Cat1      |   A   |
  |  Cat2      |   B   |
  |  Cat1      |   C   |
  |  Cat2      |   D   |
  +------------+-------+
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>DF.groupBy("category_name").agg(count("txn").as("txn_count")).show(false)
  </code></pre>
  
  <p>But this only give me the total count for each category.</p>
  
  <p>Desired output: (the format doesn't matter, just need the count)</p>
  
  <pre><code>+------------+---------------------+
  |  Category  |     txn_count       | 
  +-----===----+---------------------+  
  |  Cat1      | A(3),B(1),C(2),D(3) |  
  |  Cat2      | A(1),B(1),C(2),D(2) |
  +------------+---------------------+
  </code></pre>
  
  <p>Thank you in advance.</p>