I have a file csv file in this format, I would like to generate the average for each step:
elapsed,label
120,Step 01
260,Step 02
113,Step 03
100,Step 01
200,Step 02
103,Step 03
but am having a hard time figuring the lists out. The Python script that I am using is:
for file in sys.argv[1:]:
for row in csv.DictReader(open(file)):
label = row['label']
elapsed = row['elapsed']
print elapsed,label
I've tried
label.append(row['elapsed']) and label.append('elapsed'), but in each case I get this error
AttributeError: 'str' object has no attribute 'append'
I am unsure how to get past this error. I'm new to Python, so perhaps I am missing something in the way lists work? If I can get a list like [120,100] for step 01, I can easily sum and average it, but it is the list creation part that I am stuck on.
Edit: Sum of result list
Now, I have this:
for item in result:
for n in result[item]:
int(n)
print sum(float(result[item][n]))
but get this error
TypeError: list indices must be integers, not str
But "n" is an integer already, no ... ? Or is this referring to "item"? I think I am more confused now than before.