purpose
The reason for my interest is that we generate output tab-separated files containing values that need to be tabulated into reports. I was looking for a way to generalize the code for creating these reports. In other words:Given a list of strings describing the counts saved in each column of a CSV file, what would be the best way to automate the creation of reports of counts for individual and common categories?
For example, if a list of voters had values like Party Affiliation (D/R/O/U), Gender, Zip Code, etc, I should be able to feed in these values and get a report listing totals for Female Republicans voters[R][F], Male Democrats with Zip Code 12345 voters[D][M][12345], total unaffiliated voters voters[U], etc. And then I should be able to use the same tool to automate reports for my next list of zoo animals, with columns tabulating Species, Location, Diet...
input
- list of column ID's
- dictionary mapping column ID's to corresponding strings to use in report
- collection of totals desired for the report
output
- From input 1. and the CSV file you should be able to produce the dictionary structure containing all the totals.
- From 1 and 2 you should be able to produce a function to generate strings for a report line
- From 1, 2, 3 you should be able to produce a general sort of report. (I haven't bothered with that yet.)
links
I know there is a better way to organize this blog to enable easier searching by topic but I haven't investigated how yet. Until then, collected here are the posts where I was exploring the use of multidimensional dictionaries:- Monday, November 28, 2011
python: 2-D dictionary, somewhat dynamically filled - Tuesday, March 11, 2014 6pm
python: building 3-D dictionary - Tuesday, March 11, 2014 7pm
Python: build and initialize a dictionary from a list of lists - Friday, March 28, 2014
python: 1-d dictionary for counting hierarchical attributes - Thursday, May 23, 2013
Python: given two lists of strings, create 2-d dictionary to hold int values, initialized to 0
I ended up using a 1-D dictionary to save my multidimensional values. This worked so long as I could use a single character to express all the possibilities for each dimension, with no re-use.
No comments:
Post a Comment