On Fri, Jan 28, 2011 at 2:41 PM, Rich Shepard <[email protected]>wrote:
> Yes, this is correct. Instead of the organization above, I want each row
> to be a complete record of location, date, parameter and value. Somewhat
> analogous to transposing rows and columns in the spreadsheet, but that's
> not
> a solution.
>
Ah.. I was just pivoting the table. Updating my last and adding the ability
to specify number of header rows or label columns:
---
import csv
num_header_rows = 2
num_label_cols = 1
input = list(csv.reader(open('/path/to/file', 'r')))
output = list()
headers = [':'.join(t) for t in
zip(*input[:num_header_rows])[num_label_cols:]]
for row in input:
label = ':'.join(row[:num_label_cols])
for header,value in zip(headers, row[num_label_cols:]):
output.append(':'.join([header, label, value]))
---
HTH,
Dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.python.org/pipermail/portland/attachments/20110129/2c35feb4/attachment.html>
_______________________________________________
Portland mailing list
[email protected]
http://mail.python.org/mailman/listinfo/portland