I want to take in a few csv files, each of which would looks like this:
column1 column2 column3
18/05/16 11:19 143501 148686 40644
18/05/16 11:34 144070 144710 79585
18/05/16 11:49 134070 144713 79588
18/05/16 12:03 144070 144716 80591
18/05/16 12:13 144070 144733 79608
18/05/16 12:23 154790 144733 79608
18/05/16 12:19 144070 125753 79628
18/05/16 12:34 144070 144757 79632
I want to obtain the max and min value for each column in each csv file (excluding the date/time column) and put the data into a structure something like this:
{
'csvfile1' :[{
"column1": [{
"max": "154790"
"min": "134070"
}],
"column2": [{
"max": "148686"
"min": "125753"
}],
"column3": [{
"max": "80591"
"min": "40644"
}]
}],
'csvfile2' :[{
<same type of information here>
}],
'csvfile3' :[{
<same type of information here>
}]
}
This is my script so far:
max_min_data={}
for name in csvfile_names:
f = open(name+'.csv', "r")
#Only want to check columns 1 to 3 not the date/time
for number in range(1,3):
f.seek(0)
column_names = next(f) next(f) # Skip header
max_value = max(int(row[number]) for row in csv.reader(f))
min_value = min(int(row[number]) for row in csv.reader(f))
max_min_data[name]=[column_names[number]]
max_min_data[name][column_names[number]]=['max','min']
max_min_data[name][column_names[number]]['max']=max_value
max_min_data[name][column_names[number]]['min']=min_value
print "MAX:"
print '\t\t'+str(max_value)
print "MIN:"
print '\t\t'+str(min_value)