sorted_counties_list = list()
# a list of list of dicts
for row in state_list:
    # a list of dicts
    sorted_counties = sorted(row, key=itemgetter('c'))
    sorted_counties_list.append(sorted_counties)

# list of list of dicts
flattened = [val for sublist in sorted_counties_list for val in sublist]
sorted_issuers = sorted(flattened, key=itemgetter('s'))

# find the number of counties w/ only one insurance provider
# first group by county and tally count of insurers
data_grp = collections.defaultdict(list)

for row in sorted_issuers:
    data_grp[row['id']].append(row['i'])

issuers_count = list()
for k,v in data_grp.items():
    att = dict()
    att['Number of Issuers'] = len(v)
    att['Issuers'] = v
    att['County'] = k
    issuers_count.append(att)

# STEP FIVE: Write to file
c.write_dict(sorted_issuers, 'filtered-csvs/2015-issuers-filtered.csv')
c.write_dict(issuers_count, 'filtered-csvs/PROBLEM-count.csv')
sorted_counties_list = list()
# a list of list of dicts
for row in state_list:
    # a list of dicts
    sorted_counties = sorted(row, key=itemgetter('c'))
    sorted_counties_list.append(sorted_counties)

# list of list of dicts
flattened = [val for sublist in sorted_counties_list for val in sublist]
sorted_issuers = sorted(flattened, key=itemgetter('s'))

# find the number of counties w/ only one insurance provider
# first group by county and tally count of insurers
data_grp = collections.defaultdict(list)

for row in sorted_issuers:
    data_grp[row['id']].append(row['i'])

issuers_count = list()
for k, v in data_grp.items():
    att = dict()
    att['Number of Issuers'] = len(v)
    att['Issuers'] = v
    att['County'] = k
    issuers_count.append(att)

# STEP FOUR: Write to file
c.write_dict(sorted_issuers, 'filtered-csvs/test14-issuers-filtered.csv')
c.write_dict(issuers_count, 'filtered-csvs/test14-count.csv')
Exemplo n.º 3
0
for row in data:
    data_grp[row['f']].append(row['i'])

# get count of issuers by fips code
issuers_by_county = list()
for k, v in data_grp.items():
    att = dict()
    # all issuers in a county
    att['ict'] = len(v)
    counter = collections.Counter(v)
    # convert counter object to dict
    counter_dict = dict(counter.items())
    # split dict by key into a list of dicts
    chunks = [counter_dict.iteritems()]
    split = (dict(ifilter(None, v)) for v in izip_longest(*chunks))
    split_list = list(split)
    # sort our list of dicts
    sorted_split = sorted(split_list)
    # split up our dicts into one dict per county
    for row in sorted_split:
        key = ''.join(row.keys())
        value = ''.join(str(v) for v in row.values())
    att['f'] = k
    issuers_by_county.append(att)

# print issuers_by_county

# STEP TWO: Write to file
c.write_dict(issuers_by_county, '2017-issuers-grouped.csv')
sorted_counties_list = list()
# a list of list of dicts
for row in state_list:
    # a list of dicts
    sorted_counties = sorted(row, key=itemgetter('c'))
    sorted_counties_list.append(sorted_counties)

# list of list of dicts
flattened = [val for sublist in sorted_counties_list for val in sublist]
sorted_issuers = sorted(flattened, key=itemgetter('s'))

# find the number of counties w/ only one insurance provider
# first group by county and tally count of insurers
data_grp = collections.defaultdict(list)

for row in sorted_issuers:
    data_grp[row['id']].append(row['i'])

issuers_count = list()
for k, v in data_grp.items():
    att = dict()
    att['Number of Issuers'] = len(v)
    att['Issuers'] = v
    att['County'] = k
    issuers_count.append(att)

# STEP FIVE: Write to file
c.write_dict(sorted_issuers, 'filtered-csvs/2015-issuers-filtered.csv')
c.write_dict(issuers_count, 'filtered-csvs/PROBLEM-count.csv')
Exemplo n.º 5
0
                's': fips['s'],
                'f': fips['f'],
                'id': fips['id']
            }
            joined_data.append(entry)

# print joined_data

# identify where the join was unsuccessful
joined = list()
for row in joined_data:
    joined.append(row['id'])

orig = list()
for row in aca_2017:
    orig.append(row['id'])

unmatched = list()
for row in orig:
    if row not in joined:
        unmatched.append(row)

unmatched_unique = list(set(unmatched))
for row in unmatched_unique:
    print row

print len(joined), len(orig)

# STEP THREE: Write to file
c.write_dict(joined_data, 'fips-join/2017-joined.csv')
# a list of list of dicts
for row in state_list:
    # a list of dicts
    sorted_issuers = sorted(row, key=itemgetter('c'))
    sorted_issuers_2017.append(sorted_issuers)

# list of list of dicts
flattened = [val for sublist in sorted_issuers_2017 for val in sublist]
sorted_issuers_2017_list = sorted(flattened, key=itemgetter('s'))

# find the number of counties w/ only one insurance provider
# first group by county and tally count of insurers
data_grp = collections.defaultdict(list)

for row in sorted_issuers_2017_list:
    data_grp[row['id']].append(row['i'])

issuers_count = list()
for k,v in data_grp.items():
    att = dict()
    att['Number of Issuers'] = len(v)
    att['Issuers'] = v
    att['County'] = k
    issuers_count.append(att)

# print issuers_count

# STEP FIVE: Write to file
c.write_dict(sorted_issuers_2017_list, 'filtered-csvs/2017-issuers-filtered.csv')
c.write_dict(issuers_count, 'filtered-csvs/2017-count.csv')
sorted_counties_list = list()
# a list of list of dicts
for row in state_list:
    # a list of dicts
    sorted_counties = sorted(row, key=itemgetter('c'))
    sorted_counties_list.append(sorted_counties)

# list of list of dicts
flattened = [val for sublist in sorted_counties_list for val in sublist]
sorted_issuers = sorted(flattened, key=itemgetter('s'))

# find the number of counties w/ only one insurance provider
# first group by county and tally count of insurers
data_grp = collections.defaultdict(list)

for row in sorted_issuers:
    data_grp[row['id']].append(row['i'])

issuers_count = list()
for k,v in data_grp.items():
    att = dict()
    att['Number of Issuers'] = len(v)
    att['Issuers'] = v
    att['County'] = k
    issuers_count.append(att)

# STEP FOUR: Write to file
c.write_dict(sorted_issuers, 'filtered-csvs/test14-issuers-filtered.csv')
c.write_dict(issuers_count, 'filtered-csvs/test14-count.csv')