Skip to content
Snippets Groups Projects
Commit dae64383 authored by nugentj3's avatar nugentj3
Browse files

Update censusdata readability per issue#5

parent 0788d5fc
No related branches found
No related tags found
No related merge requests found
source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -27,3 +27,26 @@ def census_cut(tracts, data):
len(mask), len(data.index)
result = data[mask]
return result
def data_split(data):
data_dict = {}
for row in data.index:
split_row = re.split('> |, ', str(row))[:-1]
data_dict[str(row)] = split_row
data_ref = pd.DataFrame.from_dict(data_dict, orient='index', columns=['Block Group', 'Census Tract', 'County', 'State: Summary Level', 'State Code', 'County Code', 'Tract'])
data_ref['TOTAL POPULATION'] = 0
data_ref['Block Group'] = data_ref['Block Group'].apply(lambda x: int(x.split()[-1]))
data_ref['Census Tract'] = data_ref['Census Tract'].apply(lambda x: float(x.split()[-1]))
data_ref['State: Summary Level'] = data_ref['State: Summary Level'].apply(lambda x: [x.split(':')[i] for i in (0, -1)])
data_ref['State Code'] = data_ref['State Code'].apply(lambda x: int(x.split(':')[-1]))
data_ref['County Code'] = data_ref['County Code'].apply(lambda x: int(x.split(':')[-1]))
data_ref['Tract'] = data_ref['Tract'].apply(lambda x: int(x.split(':')[-1]))
return data_ref
# -
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment