title: How to group by multiple columns and collect in list in PySpark?
body: <p>Here is my problem:
  I've got this RDD:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>a = [[u'PNR1',u'TKT1',u'TEST',u'a2',u'a3'],[u'PNR1',u'TKT1',u'TEST',u'a5',u'a6'],[u'PNR1',u'TKT1',u'TEST',u'a8',u'a9']]
  
  rdd= sc.parallelize (a)
  </code></pre>
  
  <p>Then I try :</p>
  
  <pre class="lang-python prettyprint-override"><code>rdd.map(lambda x: (x[0],x[1],x[2], list(x[3:])))
  
  .toDF(["col1","col2","col3","col4"])
  
  .groupBy("col1","col2","col3")
  
  .agg(collect_list("col4")).show
  </code></pre>
  
  <p>Finally I should find this:</p>
  
  <blockquote>
  <pre class="lang-python prettyprint-override"><code>[col1,col2,col3,col4]=[u'PNR1',u'TKT1',u'TEST',[[u'a2',u'a3'][u'a5',u'a6'][u'a8',u'a9']]]
  </code></pre>
  </blockquote>
  
  <p>But the problem is that I can't collect a list.</p>
  
  <p>If anyone can help me I will appreciate it</p>