title: Python - How to Create Dictionary from CSV data file using column headings
body: <p>I am trying to create a function that accepts the name of a .csv data file and a list of strings representing column headings in that file and return a dict object with each key being a column heading and the corresponding value being a numpy array of the values in that column of the data file.</p>
  
  <p>My code right now:</p>
  
  <pre><code>def columndata(filename, columns):
  d = dict()
  for col in columns:
  with open(filename) as filein:
      reader = csv.reader(filein)
          for row in reader:
             if col in row:
                 d.append(row)
  return d
  </code></pre>
  
  <p>The sample CSV looks like:</p>
  
  <pre><code>test1,test2
  3,2
  1,5
  6,47
  1,4
  </code></pre>
  
  <p>The columns file looks like:</p>
  
  <pre><code>cols = ['test1', 'test2']
  </code></pre>
  
  <p>The end result should be a dictionary like this:</p>
  
  <pre><code>{'test1':[3,1,6,1], 'test2':[2, 5, 4, 4]}
  </code></pre>