title: Python csv columns to JSON
body: <p>I have the following csv</p>
  
  <pre><code>id, o1, o2, o3
  'jess', 1.0, 4, 0.3
  'jill', 0, 5, 0.123
  'jamie', -3, 0.2, 1.0
  </code></pre>
  
  <p>and would like it in a nested json with each column as a json keyed on the header name:</p>
  
  <pre><code>myjson = {
      "o1": {"jess": 1.0, "jill":   0, "jamie": -3}, 
      "o2": {"jess":   4, "jill":   5, "jamie": 0.2}, 
      "o3": {"jess": 0.3, "jill": 0.2, "jamie": 1.0}, 
  </code></pre>
  
  <p>Not sure the best (most pythonic) way to do this. Here is my first attempt:</p>
  
  <pre><code>import csv
  with open(myfile, "r") as f:
      reader = csv.reader(f, delimiter=',', quotechar='"')
      first = True
      for line in reader:
          if first:
              myjson = {key: dict() for key in line}
              header = list(line)
              first = False
          for i in range(len(header)):
              id = line[0]
              myjson[header[i+1]][id] = line[i+1]
  </code></pre>
  
  <p>I assume there is a better way to do this.</p>
  
  <p><strong>Edit:</strong> Should've specified this earlier but I do NOT want to use anything like Pandas. This needs to be super fast with minimal package dependencies. </p>