Note that there are some explanatory texts on larger screens.

plurals
  1. POformatting python output file in such a way that columns can be accessed later
    primarykey
    data
    text
    <p>In the program I am working on I am reading in data from a .xls filethat looks like this</p> <pre><code>2012-SEP-27 04:35:00 0.035173 0.019666 0.001566 -0.002356 0.028054 0.009819 -9999.000000 0.036353 0.021943 0.003582 -0.0006520.025411 0.009548 -9999.000000 0.035703 0.019268 0.003582 -0.0005340.040426 0.010700 -9999.000000 56.904729 95.722267 7.827207 </code></pre> <p>braking it into columns doing some screening of the numbers (this includes grouping certain columns together into 'filters') and then trying to write it back to another .xls file. I can write it to a file fine and the output file <em>looks</em> the same as the input file, but when I try to access separate columns I either can't (it sees the whole thing as a column) or I can only access it character by character. </p> <p>I've tried formatting the output a number of ways including:</p> <pre><code>AA = ('{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16} {17} {18} {19} {20} {21} {22} {23} {24} {25}'.format(date, time, filter1[0], filter1[1], filter1[2], filter2[0], filter2[1], filter2[2], filter3[0], filter3[1], filter3[2], filter4[0], filter4[1], filter4[2], filter5[0], filter5[1], filter5[2], filter6[0], filter6[1], filter6[2], filter7[0], filter7[1], filter7[2], LZA, SZA, LAM) + '\n') AA = [date, time, float(filter1[0]), float(filter1[1]), float(filter1[2]), filter2[0], filter2[1], filter2[2], filter3[0], filter3[1], filter3[2], filter4[0], filter4[1], filter4[2], filter5[0], filter5[1], filter5[2], filter6[0], filter6[1],filter6[2], filter7[0], filter7[1],filter7[2],LZA, SZA, LAM] AA = [(date, time, filter1[0], filter1[1], filter1[2], filter2[0], filter2[1], filter2[2], filter3[0], filter3[1], filter3[2], filter4[0], filter4[1], filter4[2], filter5[0], filter5[1], filter5[2], filter6[0], filter6[1], filter6[2], filter7[0], filter7[1], filter7[2], LZA, SZA, LAM)] </code></pre> <p>I'm looking for some general help on writing data into a file in such a way that it is accessible by columns, the code I'm working on is hard to explain concisely so general examples are fine. I am new to python and appreciate your help and patience </p> <p>edit</p> <pre><code> writer = csv.writer(outputfile, delimiter = '\t') row = [date, time] row.extend(map(float, filter1)) for filter in (filter2, filter3, filter4, filter5, filter6, filter7): row.extend(filter) row.extend([LZA, SZA, LAM]) writer.writerow(row) </code></pre> <p>gives me an output that looks like</p> <pre><code>2012-SEP-27 04:35:00 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -.0 56.904729 95.722267 "7.827207 " 2012-SEP-27 04:39:00 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 -9999.0 0.0 -9999.0 56.007862 96.708467 "1.784808 " 2012-SEP-27 04:43:00 0.036885 0.038065 0.047741 0.021099 0.0 0.035384 0.034978 0.045806 0.019952 0.013064 0.021955 " 2012-SEP-27 04:47:00 0.038996 0.039075 0.04026 0.020357 0.012688 .036156 0.033027 0.011406 0.011693 0.011979 -9999.0 -9999.0 -9999.0 5 " 2012-SEP-27 04:51:00 -9999.0 -9999.0 -9999.0 0.019505 0.016133 0.018253 146 0.043547 0.012732 0.014486 0.015731 -9999.0 -9999.0 -9999.0 5 " </code></pre> <p>I am trying to access each column using</p> <pre><code>from __future__ import division import csv v = open("Pt_2_Test_Data.csv", 'wb') with open("outputfile.csv", 'rb') as w: reader = csv.reader(w, delimiter = '\t', quotechar = '|') for row in w: columns = row.split(',') date = columns[0] time = columns[1] </code></pre> <p>print date will give me the dates, however anything other then columns[0] gives this error</p> <pre><code> time = columns[1] IndexError: list index out of range </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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