How can I ensure all OrderedDicts in my dictionary have the complete set of all keys, so that a CSV can be generated from it?
So to go from this:
unaggregated = {
1: OrderedDict([
('column_a', 'foo'),
('column_b', 'bar'),
]),
2: OrderedDict([
('column_a', 'baz'),
]),
}
to this:
aggregated = {
1: OrderedDict([
('column_a', 'foo'),
('column_b', 'bar'),
]),
2: OrderedDict([
('column_a', 'baz'),
('column_b', None),
]),
}
I'm generating my CSV like so, perhaps I'm over complicating the data structure.
fieldnames = next(iter(aggregated.values())).keys()
writer = csv.DictWriter(output_file, fieldnames)
writer.writeheader()
for id in aggregated:
writer.writerow(aggregated[id])
Thanks!