[portland] Reformatting Data Files
rshepard at appl-ecosys.com
Tue Feb 1 21:46:31 CET 2011
On Fri, 28 Jan 2011, Kyle Jones wrote:
> It isn't anything pretty, but I think this might be similar:
What I still need to figure out is why csv.writer() is not writing proper
delimited output. Here's an example of output lines:
JCM-20B,2008-11-13,Depth to Water,97.08
JCM-20B,2008-11-13,Total Dissolved Solids,211
Notice that the third item is not quoted unless the text contains a comma.
What I want for output is to have all text fields (that is, all but the last
one) quoted, preferably with single quotes to keep postgres happy.
This output is produced by:
outfile = open('out.csv', 'w')
outdata = csv.writer(outfile)
for row in indata:
for i, location in enumerate(loc):
if i == 0:
outdata.writerow([location, sampdate[i], row, row[i]])
When I change the csv.writer() method to 'csv.writer(outfile, quotechar =
"'", delimiter = ':')' no text is quoted, including Alkalinity, Bicarbonate
What have I missed in reading the csv module page?
More information about the Portland