Mercurial > hg > numerics
changeset 180:69543d62ae7a
more split stubbing
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 09 Aug 2016 14:34:31 -0700 |
parents | f63194f81f7d |
children | 4f474ceb9beb |
files | numerics/split_table.py numerics/table.py |
diffstat | 2 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/numerics/split_table.py Tue Aug 09 14:03:33 2016 -0700 +++ b/numerics/split_table.py Tue Aug 09 14:34:31 2016 -0700 @@ -5,6 +5,8 @@ """ # imports +import argparse +import csv import chunk import sys import table @@ -34,7 +36,12 @@ # read CSV data = parser.read_table() - print 'hi' + header = data[0].keys() + + for index, row in enumerate(data): + print '{index}'.format(index=index) + + output_data = [list(header)] if __name__ == '__main__': main()
--- a/numerics/table.py Tue Aug 09 14:03:33 2016 -0700 +++ b/numerics/table.py Tue Aug 09 14:34:31 2016 -0700 @@ -12,6 +12,7 @@ import os import sys import time +from collections import OrderedDict string = (str, unicode) @@ -56,7 +57,7 @@ duplicate_fields = duplicates(*header) if duplicate_fields: raise AssertionError("Duplicate header fields found: {duplicates}".format(duplicates=', '.join(duplicate_fields))) - return [dict(zip(header, row)) + return [OrderedDict(zip(header, row)) for row in data] @@ -100,16 +101,18 @@ data = read_table(self.options.input, verbose=self.options.verbose) - + if not data: + parser.error("No data found: {}".format(self.options.intput)) if self.options.columns: + header = data[0].keys() missing = [column for column in self.options.columns if column not in header] if missing: self.error("Columns not found in header: {0}".format(", ".join(missing))) header = options.columns - data = [dict(zip(header, - [row[column] for column in header])) + data = [OrderedDict(zip(header, + [row[column] for column in header])) for row in data] return data