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.
My code right now:
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
The sample CSV looks like:
test1,test2
3,2
1,5
6,47
1,4
The columns file looks like:
cols = ['test1', 'test2']
The end result should be a dictionary like this:
{'test1':[3,1,6,1], 'test2':[2, 5, 4, 4]}