title: Covert spark dataframe to Scala Map collection
body: <p>I have the dataframe like below.</p>
  <pre><code>scala&gt; df.show
  +---+-------+
  |key|  count|
  +---+-------+
  | 11| 100212|
  | 12| 122371|
  | 13| 235637|
  | 14|  54923|
  | 15|   9785|
  | 16|   5217|
  +---+-------+
  
  </code></pre>
  <p>I am looking at the ways to convert it into a Map like below. Please help.</p>
  <pre><code>Map(
  &quot;11&quot; -&gt; &quot;100212&quot;,
  &quot;12&quot; -&gt; &quot;122371&quot;,
  &quot;13&quot; -&gt; &quot;235637&quot;,
  &quot;14&quot; -&gt; &quot;54923&quot;,
  &quot;15&quot; -&gt; &quot;9785&quot;,
  &quot;16&quot; -&gt; &quot;9785&quot;
  )
  </code></pre>