I have a CSV file that looks like this:
compound, x1data,y1data,x2data,y2data
a,1,2,3,4
a,9,10,11,12
b,5,6,7,8
b,4,5,6,7
I would like to create a dictionary of lists where the compound is the key and for each compound I get a list of x1data, y1data, x2data, and y2data.
I believe it would look something like this:
my_dict = {
'a': {'x1data':[1,9],'y1data':[2,10],'x2data':[3,11],'y2data':[4,12]},
'b':{'x1data':[5,4],'y1data':[6,5],'x2data':[7,6],'y2data':[8,7]}
}
Ultimately I want to plot x1data vs y1data and x2data vs y2data for each of the compounds.
I've tried this which correctly makes a dictionary where the keys are compounds, but it doesn't give me a list of values (just the last value in the csv.
my_dict = {}
with open(filename, 'r') as infile:
reader = csv.DictReader(infile)
for row in reader:
key = row.pop('compound')
my_dict[key] = row