title: Create a dataframe from a hashmap with keys as column names and values as rows in Spark
body: <p>I have a dataframe and I have a column which is a map in dataframe like this -</p>
  
  <pre><code>scala&gt; df.printSchema
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>root
   |-- A1: map (nullable = true)
   |    |-- key: string
   |    |-- value: string (valueContainsNull = true)
  </code></pre>
  
  <p>I need to select all the keys from dataframe as column name and values as rows.</p>
  
  <p>For eg:
  Let say I have 2 records like this-</p>
  
  <pre class="lang-none prettyprint-override"><code>1. key1 -&gt; value1, key2 -&gt; value2, key3 -&gt; value3 ....
  2. key1 -&gt; value11, key3 -&gt; value13, key4 -&gt; value14 ...
  </code></pre>
  
  <p>I want the output dataframe as</p>
  
  <pre class="lang-none prettyprint-override"><code>key1             key2                 key3             key4
  value1           value2               value3            null
  value11          null                 value13           value14
  </code></pre>
  
  <p>How can I do this?</p>