csv - Compare column name, then compare row data in Python -
so trying have csv file looks this:
"test_name", "mean", "median", "std_dev" "data name 1", 50, 75, 10 "data name 2", 52, 80, 11 "data name 1", 53, 79, 9 "data name 2", 55, 78, 8 "data name 3", 54, 77, 7 "data name 3", 53, 71, 7 "data name 1", 51, 72, 8
so right now, have program finds if test name equal each other. because if have same data name, want compare data have.
import csv csvfile = 'some.csv' data = {} open('some.csv') f: reader = csv.dictreader(f) row in reader: (k,v) in row.items(): try: data[k].append(v) except keyerror: data[k] = [v] testnames = data['test_name'] mean = data['mean'] median = data['median'] std = data['stdev'] val in testnames: val2 in testnames: if val == val2: index = testnames.index(val) index2 = testnames.index(val2) mediantemp = median[index] mediantemp2 = median[index2] if mediantemp2 > mediantemp: sub = mediantemp2 - mediantemp if sub > 100: print "uh oh! @ ", val, "and ", val2 names
maybe, i'm doing little far off here. looking compare medians of data has same test name. struggling being able row data comparison after have compared test_names. have part working.
******* edit ********* trying use index() find element location now.
now issue having index , index2 exact same value. rather data name 1 giving index 0 , next data name 1 giving index2 of 2. both give 0.
any suggestions appreciated.
thanks :)
you can loop on index of testnames
instead use indices access row data
for in range(len(testnames)): j in range(len(testnames)): if != j , testnames[i] == testnames[j]: # access row data using: data['median'][i] data['median'][j]
Comments
Post a Comment