Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- # Load the CSV
- inv = []
- with open("/home/trapezoid/code/foo/inv") as f:
- csv_r = csv.DictReader(f, fieldnames=["County", "Serial", "Model", "Type"], quotechar='"', quoting=csv.QUOTE_ALL)
- for r in csv_r:
- inv.append(r)
- # Create a list of just county names
- all_county_names = [r['County'] for r in inv]
- # Create a dict to hold the data as we iterate through the county hardware
- county_data = {}
- # Iterate through each county, and create a nested dictionary. Top level dict keys are the county names, the nested dict is a map of hardware type to hardware count
- for county in all_county_names:
- county_inv = [r for r in inv if r['County'] == county]
- county_counts = defaultdict(int)
- for x in county_inv:
- if not x['Type']:
- x['Type'] = ''
- # Making things easier by concatenating the HW model to HW type, since the same HW can sometimes be used for different things (i.e., ADJ clients and EMS clients)
- county_counts[x['Model'] + '-' + x['Type']] += 1
- county_data[county] = county_counts
- # Create an empty list to hold the names of any counties that match the hardware in Mesa
- full_matches = []
- # Iterate through the county data dict, and compare the HW types for each county to the HW types used in Mesa. If there's an match, add the county name to the full_matches list
- for k,v in county_data.items():
- matches = []
- for kk, vv in v.items():
- if kk in county_data['Mesa'].keys():
- matches.append(kk)
- if matches == list(county_data['Mesa'].keys()):
- full_matches.append(k)
- print(full_matches)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement