[portland] Reformatting Data Files
Rich Shepard
rshepard at appl-ecosys.com
Tue Mar 22 18:37:08 CET 2011
On Fri, 28 Jan 2011, Kyle Jones wrote:
> It isn't anything pretty, but I think this might be similar:
> http://paste.pocoo.org/show/328545/
Kyle,
This has worked flawlessly for some of the exported spreadsheet pages.
Now, however, I have some pages that include the units for the measured
parameters (e.g., mg/L) which is the third-to-last column in the postgres
table.
Since I've not used python for more than a year (and I _must_ quickly
become fluent once again), my inability to get a working change embarrasses
me and I must ask the group for help.
The original lines are:
# Write the location, the date for this column, the parameter name
# (which is the first column in this row), and the value.
if row[i] != '':
float(row[i])
outdata.writerow([location, sampdate[i], row[0], float(row[i])])
else:
row[i] = ''
outdata.writerow([location, sampdate[i], row[0]])
When the last column (item in the row list) is the unit the value is a
string, not numeric so the float() function fails. My feeble attempts to
exclude that last item from conversion have failed miserably, including:
# Write the location, the date for this column, the parameter name
# (which is the first column in this row), and the value.
if row[i] != '':
# if last column is the units name, don't convert.
for i in range(row[] - 1)
float(row[i])
outdata.writerow([location, sampdate[i], row[0], float(row[i])])
else:
row[i] = ''
outdata.writerow([location, sampdate[i], row[0]])
I've tried splitting (using row[:-1]) and other expressions, but none are
correct. Please turn me in the right direction.
TIA,
Rich
More information about the Portland
mailing list