Note that there are some explanatory texts on larger screens.

plurals
  1. POAveraging down a column of averaged data
    primarykey
    data
    text
    <p>I am writing a code in python for a project that has to accomplish a few things; 1) read in data from an xls file column by column 2) average each row of the columns in groups of three 3) then average the resulting columns</p> <p>I have accomplished 1 and 2 but can't quite seem to get 3, I think a lot of the trouble I'm having stems from the fact that I am using float however I need the numbers to 6 decimal places. Any help and patience is appreciated, I'm very new to python</p> <pre><code>v = open("Pt_2_Test_Data.xls", 'wb') #created file to write output to w = open("test2.xls") count = 0 for row in w: #read in file for line in w: columns = line.split("\t") #split up into columns date = columns[0] time = columns[1] a = columns[2] b = columns[3] c = columns[4] d = columns[5] e = columns[6] f = columns[7] g = columns[8] h = columns[9] i = columns[10] j = columns[11] k = columns[12] l = columns[13] m = columns[14] n = columns[15] o = columns[16] p = columns[17] q = columns[18] r = columns[19] s = columns[20] t = columns[21] u = columns[22] LZA = columns[23] SZA = columns[24] LAM = columns[25] count += 1 A = 0 if count != 0: # gets rid of column tiles filter1 = ((float(a) + float(b) + float(c))/3) filter1 = ("%.6f" %A) filter2 = (float(d) + float(e) + float(f))/3 filter2 = ("%.6f" %filter2) filter3 = (float(g) + float(h) + float(i))/3 filter3 = ("%.6f" %filter3) filter4 = (float(j) + float(k) + float(l))/3 filter4 = ("%.6f" %filter4) filter5 = (float(m) + float(n) + float(o))/3 filter5 = ("%.6f" %filter5) filter6 = (float(p) + float(q) + float(r))/3 filter6 = ("%.6f" %filter6) filter7 = (float(s) + float(t) + float(u))/3 filter7 = ("%.6f" %filter7) A = [filter1, filter2, filter3, filter4, filter5, filter6, filter7] A = ",".join(str(x) for x in A).join('[]') print A avg = [float(sum(col))/float(len(col)) for col in zip(*A)] print avg </code></pre> <p>I have also tried formatting the data like so:</p> <pre><code> A = ('{0} {1} {2} {3} {4} {5} {6} {7} {8}'.format(date, time, float(filter1), float(filter2), float(filter3), float(filter4), float(filter5), float(filter6), float(filter7))+'\n') # average of triplets print A </code></pre> <p>thinking I could access the values of each column and preform the necessary math on them by calling them like you would when using a dictionary, however this was unsuccessful:it seemed it was recognizing the data either as a row (so trying to access any column by [0] was out of bounds) or by the individual characters, not as a list of numbers. Is this related to using the float function? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload