title: Convert Spark DataFrame to HashMap
body: <p>I have a dataframe that looks like this:</p>
  
  <pre><code>product1 product2 difference
  123      456      0.5
  123      789      1
  456      789      0
  456      123      0.5
  789      123      1
  789      456      0
  </code></pre>
  
  <p>I would like an output that looks like this:</p>
  
  <pre><code>{'123': {'456': 0.5, '789': 1}, 456: {'123': 0.5, '789': 1}, '789': {'123': 1, '456': 0}}
  </code></pre>
  
  <p>so far I have tried <code>zipWithIndex</code> and <code>collectAsMap</code> with no luck.</p>
  
  <p>The code I have tried so far is: </p>
  
  <pre><code>val tples: RDD[(Int, (Int, Double))] = (products.rdd
    .map(r =&gt; (r(0).toString.toDouble.toInt, (r(1).toString.toDouble.toInt, r(2).toString.toDouble))))
  val lst: = tpls.groupByKey().map(r =&gt; (r._1, r._2.toSeq))
  </code></pre>
  
  <p>This gives me a list of products and differences instead of a hash map</p>