[portland] Reformatting Data Files

Ethan Furman ethan at stoneleaf.us
Fri Jan 28 21:41:30 CET 2011


Rich Shepard wrote:
>   I'll open with a mea culpa: I've done no python coding in more than a
> year, have lost most of my knowledge, and need to regain (and exceed) the
> proficiency I once had. My immediate need is to restructure data exported
> from spreadsheets as .csv files. I'm trying to use the csv module, but keep
> going around in circles trying to index each column in each row so they can
> be written to an output file with a different organization.
> 
>   Here are the first three lines of an exported file (10b20b.txt):
> 
> :'JCM-10B':'JCM-10B':'JCM-10B':'JCM-10B':'JCM-10B':'JCM-10B':'JCM-10B':
> :2004-08-16:2005-06-07:2005-08-31:2006-06-12:2006-09-21:2007-06-21:2007-12-11:
> 'Depth to Water':76.75:77.51:82.15:73.17:72.66:84.44:96.41:
   'HeightToSky':8917.72:7812.28:9153.72:8411.91:8837.51:8784.22:9244.76:
   'SomethingElse':182.98:817.82:352.99:721.57:292.38:379.28:447.92:
> 
> 
> The first two rows have NULL values for the first column (which I'll call
> param).
> 
>   The goal of the exercise is to write an output .csv file suitable for
> import to a database table. This means concatenating row 0, column 1 with
> row 1, column 1 and row 2, column 0, row 2, column 1, row 3, col 0, row 3,
> col 1, etc. In other words, I want the output to look like this:
> 
> ::'JCM-10B':'2004-08-16':'Depth to water':76.75::
> ::'JCM-10B':'2004-08-16':<next param>:<next value>::

I'm having a hard time understanding your description of what the 
second, third, etc, lines should look like...  if I carry out your table 
further, is it correct?


::'JCM-10B':'2004-08-16':'Depth to water':76.75::
::'JCM-10B':'2004-08-16':'HeightToSky':8917.72::
::'JCM-10B':'2004-08-16':'SomethingElse':182.89::


If that's correct, what happens to the remaining values on lines 3, 4, etc?

~Ethan~


More information about the Portland mailing list