[portland] Reformatting Data Files
ethan at stoneleaf.us
Tue Mar 22 21:37:49 CET 2011
Rich Shepard wrote:
> 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
> outdata.writerow([location, sampdate[i], row, float(row[i])])
How about a function that either floats your string, or returns the
string if it's not a number?
Something like this:
--> def flt_or_str(unk):
... return float(unk)
... except ValueError:
... return unk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): hello
Then your line of codes becomes:
outdata.writerow([location, sampdate[i], row, flt_or_str(row[i])])
Hope this helps!
More information about the Portland