title: Convert columns in (.csv) file to (.json) column array in Python
body: <p>I am trying to convert a (.csv) file to a .json file which is stored in the form of a column array.</p>
  <p>The <strong>input (.csv) file</strong> is:</p>
  <p><a href="https://i.stack.imgur.com/sMVpK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sMVpK.png" alt="enter image description here" /></a></p>
  <p>This is my <strong>desired result</strong>:</p>
  <pre><code>{
     &quot;wavelength&quot;:[0.033962528,0.035974933,0.03801894,0.039994474,0.041975898,0.043954162],
     &quot;n&quot;:[0.842171,0.83072,0.819753,0.809997,0.802291,0.797737],
     &quot;k&quot;:[0.090738197,0.10934279,0.13025372,0.15338756,0.17980019,0.20882868],
     &quot;alpha&quot;:[33573761.42,38194428.97,43052660.58,48194781.27,53826980.05,59703529.05],
     &quot;absorption_length&quot;:[2.98e-8,2.62e-8,2.32e-8,2.07e-8,1.86e-8,1.67e-8]
  }
  </code></pre>
  <p>I am using this <strong>script</strong>:</p>
  <pre><code>import csv
  import json
  
  with open('test.csv') as infile:
      reader = csv.DictReader(infile)
      out = [{&quot;wavelength&quot;: row['wavelength'],&quot;n&quot;: row[&quot;n&quot;], &quot;k&quot;: row[&quot;k&quot;],, &quot;alpha&quot;: [&quot;alpha&quot;]} for row in reader]
  
  with open('data.json', 'w') as outfile:
      json.dump(out, outfile)
  </code></pre>
  <p>But I am getting the following:</p>
  <pre><code>[{&quot;wavelength&quot;: &quot;0.033962528&quot;, &quot;n&quot;: &quot;0.842171&quot;, &quot;k&quot;: &quot;0.090738197&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]}, 
  {&quot;wavelength&quot;: &quot;0.035974933&quot;, &quot;n&quot;: &quot;0.83072&quot;, &quot;k&quot;: &quot;0.10934279&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]}, 
  {&quot;wavelength&quot;: &quot;0.03801894&quot;, &quot;n&quot;: &quot;0.819753&quot;, &quot;k&quot;: &quot;0.13025372&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]},
   {&quot;wavelength&quot;: &quot;0.039994474&quot;, &quot;n&quot;: &quot;0.809997&quot;, &quot;k&quot;: &quot;0.15338756&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]}, 
  {&quot;wavelength&quot;: &quot;0.041975898&quot;, &quot;n&quot;: &quot;0.802291&quot;, &quot;k&quot;: &quot;0.17980019&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]}, 
  {&quot;wavelength&quot;: &quot;0.043954162&quot;, &quot;n&quot;: &quot;0.797737&quot;, &quot;k&quot;: &quot;0.20882868&quot;, &quot;alpha&quot;: [&quot;alpha&quot;]}]
  </code></pre>
  <p>I am trying to get the desired result.</p>