I have a csv file that looks like:
a, b, c, d
1, 1, 2, 2
2, 3, 3, 4
2, 2, 1, 1
I'd like to load this csv file into a dictionary so that I can get
dict['a'] = 1, 2, 2
dict['b'] = 1, 3, 2
dict['c'] = 2, 3, 1
dict['d'] = 2, 4, 1
Is there a way to do this right at the csv reader level?
I got this far:
import csv
headers = {}
with open('file.csv') as csvfile:
reader = csv.reader(csvfile, delimiter = ',')
count = 0;
for row in reader:
if count == 0:
for field in row:
if field not in headers.keys():
headers[field] = []
count +=1
This loads the header and now I'd like to load each value in.