title: group by key value pyspark
body: <p>I'm trying to group a value (key, value) with apache spark (pyspark).
  I manage to make the grouping by the key, but internally I want to group the values, as in the following example.</p>
  
  <p>I need to group by a cout() the column GYEAR.</p>
  
  <pre><code>%pyspark
  
  rdd1 = sc.textFile("/datos/apat63_99.txt")
  
  rdd2 = rdd1.map(lambda line :  line.split(",") ).map(lambda l : (l[4],l[1],l[0]))
  
  for line in rdd2.take(6):
      print(line)
  
  ######################
  
  rdd3 = rdd2.map(lambda line:(line[0],(line[1:]) ))
  
  rddx = rdd2.groupByKey()
  rddx.take(5)
  
  </code></pre>
  
  <p>I expect the output to be:</p>
  
  <p>IN:</p>
  
  <pre><code>(u'"COUNTRY"', u'"GYEAR"', u'"PATENT"')
  (u'"BE"', u'1963', u'3070801')
  (u'"BE"', u'1964', u'3070811')
  (u'"US"', u'1963', u'3070802')
  (u'"US"', u'1963', u'3070803')
  (u'"US"', u'1963', u'3070804')
  (u'"US"', u'1963', u'3070805')
  (u'"US"', u'1964', u'3070807')
  </code></pre>
  
  <p>OUT:</p>
  
  <pre><code>(u'"BE"', [(u'1963', 1), (u'1964', 1)])
  (u'"US"', [(u'1963', 4), (u'1964', 2)])
  </code></pre>