import pandas as pd
import numpy as np
pd.set_option('display.max_rows', 500)
The data for this analysis comes from the American Community Survey's 2012 5-year data, via American Fact Finder. Specifically, it comes from tables DP03 (employment), DP04 (housing), DP05 (race), and S1701 (poverty).
def read_acs_file(path, coldict):
return pd.read_csv(path, skiprows=1, na_values=["N", "(X)"], low_memory=False)\
.rename(columns=coldict)\
.set_index([ "Geography", "Id" ])
dp03_cols = {
"Estimate; EMPLOYMENT STATUS - In labor force - Civilian labor force": "n_labor_force",
"Estimate; EMPLOYMENT STATUS - In labor force - Civilian labor force - Employed": "n_employed"
}
dp04_cols = {
"Estimate; HOUSING OCCUPANCY - Total housing units": "n_housing_units",
"Estimate; HOUSING TENURE - Occupied housing units": "n_occupied_units",
"Estimate; HOUSING TENURE - Owner-occupied": "n_owner_occupied_units",
"Estimate; HOUSING TENURE - Renter-occupied": "n_renter_occupied_units",
}
dp05_cols = {
"Estimate; SEX AND AGE - Total population": "total_pop",
"Estimate; RACE - One race - White": "white_pop",
"Estimate; RACE - One race - Black or African American": "black_pop"
}
s1701_cols = {
"Total; Estimate; Population for whom poverty status is determined": "n_poverty_universe",
"Below poverty level; Estimate; Population for whom poverty status is determined": "n_below_poverty_level"
}
dp03 = read_acs_file("../data/all-tracts/ACS_12_5YR_DP03_with_ann.csv", dp03_cols)
dp04 = read_acs_file("../data/all-tracts/ACS_12_5YR_DP04_with_ann.csv", dp04_cols)
dp05 = read_acs_file("../data/all-tracts/ACS_12_5YR_DP05_with_ann.csv", dp05_cols)
s1701 = read_acs_file("../data/all-tracts/ACS_12_5YR_S1701_with_ann.csv", s1701_cols)
joined = dp05[dp05_cols.values()]\
.join(dp04[dp04_cols.values()])\
.join(dp03[dp03_cols.values()])\
.join(s1701[s1701_cols.values()])\
joined["county"] = [ ", ".join(x.split(", ")[1:]) for x in joined.reset_index()["Geography"] ]
stl_county_ids = joined[joined["county"] == "St. Louis County, Missouri"].index.values
stl = joined.ix[stl_county_ids]
For this analysis, we're using the index of dissimilarity to measure segregation. Because we're particularly interested in segregation between black residents (people who identify as "Black or African American" as their only race) and white residents (people who identify only as non-Hispanic "White"), our calculations focus on just those residents.
def get_bwdi(tracts):
b_total = tracts["black_pop"].sum()
w_total = tracts["white_pop"].sum()
x = (tracts["black_pop"] / b_total).replace([np.inf, -np.inf], np.nan).fillna(0)
y = (tracts["white_pop"] / w_total).replace([np.inf, -np.inf], np.nan).fillna(0)
abs_dist = (x - y).apply(abs)
dist = abs_dist.sum() / 2
return dist
def get_grouped_bwdi(tracts, grouper):
grouped = tracts.groupby(grouper)
pop = grouped["total_pop"].sum()
black_pop = grouped["black_pop"].sum()
df = pd.DataFrame({
"bwdi": grouped.apply(get_bwdi),
"pop": pop,
"black_pop": black_pop,
"p_black_pop": black_pop * 1.0 / pop
})
return df
dissim = get_grouped_bwdi(joined, joined["county"])
We also want to ignore counties with small populations (less than 20,000 people), or relatively small proportions of black residents (less than 20% black).
large_black_populations = dissim[(dissim["pop"] >= 20000) & (dissim["p_black_pop"] >= 0.2)]
Given these parameters, we can construct a ranking, by black–white dissimilarity index, of the most segregated counties in the country:
large_black_populations["rank"] = large_black_populations["bwdi"].rank(ascending=False)
large_black_populations.sort("rank")[["rank", "bwdi", "pop", "p_black_pop"]]
rank | bwdi | pop | p_black_pop | |
---|---|---|---|---|
county | ||||
Wayne County, Michigan | 1 | 0.804298 | 1822469 | 0.404703 |
Cook County, Illinois | 2 | 0.782883 | 5197677 | 0.247084 |
Kings County, New York | 3 | 0.772618 | 2512740 | 0.342105 |
Milwaukee County, Wisconsin | 4 | 0.754199 | 946584 | 0.264607 |
DeKalb County, Georgia | 5 | 0.738545 | 694671 | 0.544800 |
Lake County, Indiana | 6 | 0.730679 | 495230 | 0.254611 |
Fulton County, Georgia | 7 | 0.726778 | 929535 | 0.442149 |
Essex County, New Jersey | 8 | 0.726657 | 783840 | 0.405337 |
Cuyahoga County, Ohio | 9 | 0.710899 | 1278024 | 0.296372 |
Philadelphia County, Pennsylvania | 10 | 0.704626 | 1525811 | 0.434298 |
District of Columbia, District of Columbia | 11 | 0.703653 | 605759 | 0.510538 |
St. Louis County, Missouri | 12 | 0.703343 | 999147 | 0.231452 |
Baltimore city, Maryland | 13 | 0.690520 | 620644 | 0.637053 |
Suffolk County, Massachusetts | 14 | 0.685471 | 724502 | 0.223280 |
Genesee County, Michigan | 15 | 0.680964 | 425337 | 0.203394 |
Shelby County, Tennessee | 16 | 0.677517 | 929437 | 0.519036 |
Ouachita Parish, Louisiana | 17 | 0.655953 | 153752 | 0.366707 |
Orleans Parish, Louisiana | 18 | 0.654695 | 341407 | 0.601771 |
Jefferson County, Alabama | 19 | 0.651217 | 658464 | 0.421976 |
Montgomery County, Ohio | 20 | 0.649272 | 535626 | 0.209603 |
St. Louis city, Missouri | 21 | 0.648282 | 318527 | 0.489491 |
Putnam County, Georgia | 22 | 0.627195 | 21184 | 0.270582 |
Jefferson County, Arkansas | 23 | 0.623897 | 76836 | 0.550614 |
Hamilton County, Tennessee | 24 | 0.621753 | 337023 | 0.203096 |
Hamilton County, Ohio | 25 | 0.621289 | 801350 | 0.256762 |
Jackson County, Missouri | 26 | 0.616690 | 672784 | 0.238198 |
Rapides Parish, Louisiana | 27 | 0.611237 | 131655 | 0.321393 |
Baltimore County, Maryland | 28 | 0.610232 | 807318 | 0.260507 |
Caddo Parish, Louisiana | 29 | 0.607782 | 254970 | 0.473209 |
Calcasieu Parish, Louisiana | 30 | 0.604322 | 192307 | 0.249538 |
Roanoke city, Virginia | 31 | 0.602099 | 96742 | 0.279279 |
Richmond city, Virginia | 32 | 0.597742 | 205348 | 0.499041 |
East Baton Rouge Parish, Louisiana | 33 | 0.596599 | 439662 | 0.453819 |
Mobile County, Alabama | 34 | 0.591586 | 412297 | 0.347643 |
Plaquemines Parish, Louisiana | 35 | 0.585926 | 23220 | 0.210637 |
Union County, New Jersey | 36 | 0.582829 | 536383 | 0.215790 |
Bolivar County, Mississippi | 37 | 0.582738 | 34239 | 0.656503 |
St. Clair County, Illinois | 38 | 0.580126 | 268873 | 0.302957 |
Muscogee County, Georgia | 39 | 0.576563 | 191278 | 0.451280 |
Henrico County, Virginia | 40 | 0.571759 | 307576 | 0.292341 |
Jefferson Parish, Louisiana | 41 | 0.566465 | 432706 | 0.265180 |
Franklin County, Ohio | 42 | 0.565799 | 1167484 | 0.211514 |
Mercer County, New Jersey | 43 | 0.564806 | 366442 | 0.201538 |
Bibb County, Georgia | 44 | 0.563775 | 155560 | 0.515255 |
Hinds County, Mississippi | 45 | 0.562968 | 246335 | 0.690243 |
Portsmouth city, Virginia | 46 | 0.561325 | 95786 | 0.529670 |
Monroe County, Mississippi | 47 | 0.556499 | 36912 | 0.309601 |
Dallas County, Alabama | 48 | 0.551922 | 43572 | 0.689824 |
Broward County, Florida | 49 | 0.547199 | 1761993 | 0.266777 |
Crittenden County, Arkansas | 50 | 0.545611 | 50618 | 0.510313 |
Jefferson County, Kentucky | 51 | 0.545512 | 741285 | 0.206254 |
Glynn County, Georgia | 52 | 0.541278 | 79628 | 0.256179 |
Marion County, Indiana | 53 | 0.540909 | 904535 | 0.265291 |
Tuscaloosa County, Alabama | 54 | 0.533395 | 194254 | 0.299597 |
Jefferson County, Texas | 55 | 0.531044 | 251627 | 0.335119 |
Forrest County, Mississippi | 56 | 0.525328 | 75378 | 0.363740 |
Orange County, Florida | 57 | 0.525101 | 1153795 | 0.206783 |
Mecklenburg County, North Carolina | 58 | 0.519155 | 926873 | 0.304582 |
Madison County, Alabama | 59 | 0.517145 | 334661 | 0.239953 |
Montgomery County, Alabama | 60 | 0.516464 | 229376 | 0.546688 |
Pulaski County, Arkansas | 61 | 0.512732 | 383185 | 0.349870 |
Dallas County, Texas | 62 | 0.510183 | 2379214 | 0.219668 |
Peach County, Georgia | 63 | 0.508005 | 27531 | 0.463514 |
Dougherty County, Georgia | 64 | 0.506021 | 94591 | 0.671227 |
Macon County, Alabama | 65 | 0.504566 | 21214 | 0.831291 |
Somerset County, Maryland | 66 | 0.504155 | 26402 | 0.408454 |
Calhoun County, Alabama | 67 | 0.503011 | 117834 | 0.207249 |
Guilford County, North Carolina | 68 | 0.500984 | 489576 | 0.327465 |
Prince George's County, Maryland | 69 | 0.500953 | 865443 | 0.642114 |
Leflore County, Mississippi | 70 | 0.498800 | 32196 | 0.715896 |
Yazoo County, Mississippi | 71 | 0.498727 | 28220 | 0.564281 |
Lauderdale County, Mississippi | 72 | 0.498345 | 80204 | 0.422747 |
Norfolk city, Virginia | 73 | 0.498136 | 243056 | 0.431505 |
Lowndes County, Georgia | 74 | 0.495928 | 109730 | 0.359801 |
Jackson County, Mississippi | 75 | 0.495208 | 139430 | 0.216037 |
Forsyth County, North Carolina | 76 | 0.489728 | 351368 | 0.262022 |
Davidson County, Tennessee | 77 | 0.489406 | 629113 | 0.277505 |
Washington County, Mississippi | 78 | 0.487870 | 51010 | 0.709351 |
Duval County, Florida | 79 | 0.487779 | 866431 | 0.293941 |
Adams County, Mississippi | 80 | 0.485238 | 32391 | 0.578525 |
Fort Bend County, Texas | 81 | 0.484585 | 587666 | 0.213996 |
Houston County, Alabama | 82 | 0.484188 | 101459 | 0.256774 |
Charleston County, South Carolina | 83 | 0.483825 | 352548 | 0.299131 |
Mississippi County, Arkansas | 84 | 0.483336 | 46388 | 0.341791 |
Madison County, Mississippi | 85 | 0.481968 | 95481 | 0.382223 |
Dorchester County, Maryland | 86 | 0.481816 | 32570 | 0.278078 |
Miller County, Arkansas | 87 | 0.480266 | 43449 | 0.243527 |
Edgecombe County, North Carolina | 88 | 0.479638 | 56253 | 0.572396 |
Bronx County, New York | 89 | 0.479521 | 1386364 | 0.347484 |
Assumption Parish, Louisiana | 90 | 0.478634 | 23321 | 0.306462 |
Wyandotte County, Kansas | 91 | 0.476743 | 157274 | 0.255128 |
Cherokee County, South Carolina | 92 | 0.476005 | 55351 | 0.201369 |
Madison County, Tennessee | 93 | 0.473464 | 97976 | 0.362538 |
Morehouse Parish, Louisiana | 94 | 0.472652 | 27893 | 0.471086 |
New Castle County, Delaware | 95 | 0.471390 | 539665 | 0.237898 |
Chatham County, Georgia | 96 | 0.466276 | 266344 | 0.402611 |
Natchitoches Parish, Louisiana | 97 | 0.463749 | 39434 | 0.413907 |
Pointe Coupee Parish, Louisiana | 98 | 0.462585 | 22821 | 0.365584 |
St. Charles Parish, Louisiana | 99 | 0.460446 | 52663 | 0.264854 |
Tift County, Georgia | 100 | 0.455096 | 40430 | 0.296463 |
Richland Parish, Louisiana | 101 | 0.454888 | 20785 | 0.358768 |
Georgetown County, South Carolina | 102 | 0.454814 | 60285 | 0.339222 |
Lenoir County, North Carolina | 103 | 0.453155 | 59372 | 0.406303 |
Jones County, Mississippi | 104 | 0.448573 | 67868 | 0.281782 |
Russell County, Alabama | 105 | 0.448526 | 53938 | 0.421892 |
Spalding County, Georgia | 106 | 0.448300 | 63979 | 0.329483 |
Monroe County, Georgia | 107 | 0.447728 | 26376 | 0.238854 |
Lafayette Parish, Louisiana | 108 | 0.443262 | 221602 | 0.256821 |
Christian County, Kentucky | 109 | 0.442099 | 73722 | 0.209788 |
Richland County, South Carolina | 110 | 0.438933 | 384596 | 0.458388 |
De Soto Parish, Louisiana | 111 | 0.437632 | 26695 | 0.383031 |
Escambia County, Florida | 112 | 0.436147 | 298864 | 0.223292 |
Lincoln Parish, Louisiana | 113 | 0.434515 | 46543 | 0.406334 |
Spartanburg County, South Carolina | 114 | 0.434051 | 284540 | 0.205792 |
Wake County, North Carolina | 115 | 0.433677 | 905573 | 0.208387 |
Union Parish, Louisiana | 116 | 0.433539 | 22633 | 0.267265 |
Hardeman County, Tennessee | 117 | 0.432625 | 27193 | 0.413158 |
Richmond County, Georgia | 118 | 0.432415 | 200337 | 0.544917 |
Concordia Parish, Louisiana | 119 | 0.429141 | 20624 | 0.408844 |
Lowndes County, Mississippi | 120 | 0.427887 | 59584 | 0.437030 |
Suffolk city, Virginia | 121 | 0.427848 | 84216 | 0.420039 |
Union County, Arkansas | 122 | 0.426836 | 41594 | 0.329447 |
Bowie County, Texas | 123 | 0.424988 | 92460 | 0.235248 |
Taylor County, Florida | 124 | 0.424695 | 22561 | 0.213687 |
Colquitt County, Georgia | 125 | 0.424098 | 45531 | 0.229470 |
Houston County, Texas | 126 | 0.421578 | 23512 | 0.264631 |
Chesapeake city, Virginia | 127 | 0.419093 | 223233 | 0.298966 |
Lee County, Mississippi | 128 | 0.416509 | 83235 | 0.274151 |
Harrison County, Mississippi | 129 | 0.416366 | 188110 | 0.223433 |
Bibb County, Alabama | 130 | 0.415026 | 22769 | 0.217533 |
Leon County, Florida | 131 | 0.414360 | 276506 | 0.302446 |
Cobb County, Georgia | 132 | 0.414161 | 691820 | 0.251299 |
Franklin Parish, Louisiana | 133 | 0.413908 | 20714 | 0.323018 |
Newport News city, Virginia | 134 | 0.413542 | 180831 | 0.403642 |
Durham County, North Carolina | 135 | 0.412910 | 269283 | 0.374242 |
St. Landry Parish, Louisiana | 136 | 0.412444 | 83774 | 0.412037 |
Washington Parish, Louisiana | 137 | 0.412253 | 47025 | 0.307836 |
Alachua County, Florida | 138 | 0.408445 | 247973 | 0.200808 |
Iberia Parish, Louisiana | 139 | 0.408035 | 73527 | 0.317312 |
Waller County, Texas | 140 | 0.406518 | 42894 | 0.241246 |
McDuffie County, Georgia | 141 | 0.406244 | 21762 | 0.405707 |
Hempstead County, Arkansas | 142 | 0.405936 | 22548 | 0.302067 |
Ascension Parish, Louisiana | 143 | 0.405898 | 107647 | 0.224047 |
St. John the Baptist Parish, Louisiana | 144 | 0.402422 | 45741 | 0.534575 |
Gregg County, Texas | 145 | 0.402328 | 121451 | 0.200813 |
Bossier Parish, Louisiana | 146 | 0.401591 | 117742 | 0.213696 |
Lynchburg city, Virginia | 147 | 0.400932 | 75657 | 0.288261 |
Hopewell city, Virginia | 148 | 0.400921 | 22501 | 0.387716 |
Upson County, Georgia | 149 | 0.400585 | 27061 | 0.279369 |
Harrison County, Texas | 150 | 0.398357 | 65958 | 0.226750 |
Neshoba County, Mississippi | 151 | 0.397863 | 29682 | 0.208578 |
Lincoln County, Mississippi | 152 | 0.397379 | 34850 | 0.305136 |
Chesterfield County, Virginia | 153 | 0.393437 | 316895 | 0.222790 |
Wayne County, Mississippi | 154 | 0.392630 | 20754 | 0.389467 |
Tangipahoa Parish, Louisiana | 155 | 0.389252 | 121209 | 0.301496 |
Alexandria city, Virginia | 156 | 0.387710 | 140337 | 0.218039 |
Cumberland County, New Jersey | 157 | 0.386009 | 156864 | 0.201793 |
Pike County, Mississippi | 158 | 0.385795 | 40300 | 0.517022 |
Lo�za Municipio, Puerto Rico | 159 | 0.384735 | 29997 | 0.350468 |
Florence County, South Carolina | 160 | 0.384263 | 136714 | 0.411750 |
Wayne County, North Carolina | 161 | 0.383850 | 122419 | 0.317492 |
Halifax County, North Carolina | 162 | 0.382943 | 54693 | 0.513302 |
St. Mary Parish, Louisiana | 163 | 0.381279 | 54285 | 0.319628 |
Hampton city, Virginia | 164 | 0.378780 | 137471 | 0.505758 |
Anderson County, Texas | 165 | 0.378243 | 58269 | 0.213681 |
Tallapoosa County, Alabama | 166 | 0.377657 | 41534 | 0.273198 |
Thomas County, Georgia | 167 | 0.376703 | 44715 | 0.372358 |
Craven County, North Carolina | 168 | 0.376087 | 102904 | 0.218310 |
Troup County, Georgia | 169 | 0.375663 | 67146 | 0.338248 |
Grenada County, Mississippi | 170 | 0.374996 | 21886 | 0.425340 |
Evangeline Parish, Louisiana | 171 | 0.373234 | 33989 | 0.283121 |
Charlottesville city, Virginia | 172 | 0.372480 | 43223 | 0.200379 |
Coahoma County, Mississippi | 173 | 0.371182 | 26099 | 0.753707 |
Petersburg city, Virginia | 174 | 0.369770 | 32226 | 0.795165 |
Bell County, Texas | 175 | 0.369221 | 310155 | 0.212777 |
St. James Parish, Louisiana | 176 | 0.369141 | 21978 | 0.505779 |
Williamsburg County, South Carolina | 177 | 0.369023 | 34361 | 0.663950 |
Talladega County, Alabama | 178 | 0.368809 | 82194 | 0.325596 |
Wicomico County, Maryland | 179 | 0.367318 | 98940 | 0.237204 |
Lauderdale County, Tennessee | 180 | 0.365987 | 27772 | 0.352441 |
Webster Parish, Louisiana | 181 | 0.360652 | 41156 | 0.336573 |
Laurens County, Georgia | 182 | 0.360606 | 48264 | 0.358673 |
Clarke County, Georgia | 183 | 0.357516 | 117762 | 0.261629 |
Prince George County, Virginia | 184 | 0.354616 | 36013 | 0.323605 |
Cleveland County, North Carolina | 185 | 0.352498 | 97890 | 0.209174 |
Avoyelles Parish, Louisiana | 186 | 0.352491 | 41925 | 0.294955 |
Wilson County, North Carolina | 187 | 0.352220 | 81020 | 0.383103 |
Lancaster County, South Carolina | 188 | 0.351500 | 76364 | 0.239930 |
Henry County, Georgia | 189 | 0.350898 | 203185 | 0.364166 |
Newton County, Georgia | 190 | 0.348730 | 100047 | 0.401261 |
Edgefield County, South Carolina | 191 | 0.348337 | 26763 | 0.379703 |
Escambia County, Alabama | 192 | 0.346368 | 38122 | 0.322124 |
Monroe County, Alabama | 193 | 0.345853 | 22993 | 0.414648 |
Robeson County, North Carolina | 194 | 0.340705 | 133920 | 0.240860 |
Prince William County, Virginia | 195 | 0.340636 | 404011 | 0.200029 |
Clark County, Arkansas | 196 | 0.340088 | 23050 | 0.238351 |
Goochland County, Virginia | 197 | 0.338459 | 21496 | 0.205294 |
Danville city, Virginia | 198 | 0.337675 | 43185 | 0.483385 |
Leake County, Mississippi | 199 | 0.337365 | 23563 | 0.407249 |
Hart County, Georgia | 200 | 0.333794 | 25277 | 0.200498 |
Gadsden County, Florida | 201 | 0.333719 | 46823 | 0.555475 |
Jones County, Georgia | 202 | 0.332472 | 28638 | 0.250960 |
Franklin County, North Carolina | 203 | 0.332213 | 60470 | 0.258012 |
Cumberland County, North Carolina | 204 | 0.332161 | 319329 | 0.358627 |
Beaufort County, North Carolina | 205 | 0.331435 | 47542 | 0.261663 |
Coffee County, Georgia | 206 | 0.329934 | 42566 | 0.273505 |
Sumter County, South Carolina | 207 | 0.329595 | 107279 | 0.465674 |
Darlington County, South Carolina | 208 | 0.328426 | 68500 | 0.412584 |
Columbia County, Arkansas | 209 | 0.327962 | 24644 | 0.368122 |
Warren County, Mississippi | 210 | 0.326286 | 48419 | 0.469093 |
Butler County, Alabama | 211 | 0.325686 | 20730 | 0.432272 |
Duplin County, North Carolina | 212 | 0.325065 | 58510 | 0.254452 |
Charles County, Maryland | 213 | 0.323441 | 147107 | 0.407030 |
Lee County, Alabama | 214 | 0.323364 | 140938 | 0.229349 |
Gwinnett County, Georgia | 215 | 0.322920 | 810624 | 0.233188 |
Elbert County, Georgia | 216 | 0.318710 | 20103 | 0.302592 |
Laurens County, South Carolina | 217 | 0.317420 | 66623 | 0.250499 |
Fredericksburg city, Virginia | 218 | 0.316005 | 24932 | 0.234638 |
Chambers County, Alabama | 219 | 0.315150 | 34228 | 0.391755 |
Randolph County, Alabama | 220 | 0.314582 | 22843 | 0.208291 |
Clayton County, Georgia | 221 | 0.312916 | 262066 | 0.656022 |
Rockdale County, Georgia | 222 | 0.311594 | 85008 | 0.457463 |
Sumter County, Georgia | 223 | 0.311186 | 32425 | 0.518273 |
Chester County, South Carolina | 224 | 0.311016 | 33028 | 0.379436 |
Barnwell County, South Carolina | 225 | 0.310634 | 22523 | 0.450562 |
Pitt County, North Carolina | 226 | 0.309800 | 167951 | 0.339266 |
Orangeburg County, South Carolina | 227 | 0.305808 | 92229 | 0.624240 |
Douglas County, Georgia | 228 | 0.305010 | 132124 | 0.394546 |
Marshall County, Mississippi | 229 | 0.302476 | 37019 | 0.475080 |
Ouachita County, Arkansas | 230 | 0.300262 | 25894 | 0.402526 |
Greenwood County, South Carolina | 231 | 0.299475 | 69531 | 0.303548 |
Abbeville County, South Carolina | 232 | 0.299464 | 25387 | 0.281404 |
Marion County, Mississippi | 233 | 0.297796 | 26810 | 0.328460 |
Aiken County, South Carolina | 234 | 0.296925 | 160169 | 0.249162 |
Clarendon County, South Carolina | 235 | 0.295725 | 34746 | 0.500432 |
Berkeley County, South Carolina | 236 | 0.295267 | 179773 | 0.252190 |
Copiah County, Mississippi | 237 | 0.294432 | 29324 | 0.513743 |
West Baton Rouge Parish, Louisiana | 238 | 0.293477 | 23748 | 0.367062 |
Wayne County, Georgia | 239 | 0.292334 | 30157 | 0.208144 |
Person County, North Carolina | 240 | 0.292131 | 39322 | 0.274681 |
Phillips County, Arkansas | 241 | 0.290771 | 21646 | 0.627691 |
Harnett County, North Carolina | 242 | 0.289513 | 115559 | 0.206899 |
Richmond County, North Carolina | 243 | 0.289083 | 46608 | 0.305420 |
Elmore County, Alabama | 244 | 0.288270 | 79330 | 0.202143 |
Sunflower County, Mississippi | 245 | 0.288234 | 29230 | 0.729730 |
Northampton County, North Carolina | 246 | 0.287806 | 21959 | 0.571793 |
Vance County, North Carolina | 247 | 0.287607 | 45183 | 0.500609 |
Ware County, Georgia | 248 | 0.287483 | 36099 | 0.298014 |
Bladen County, North Carolina | 249 | 0.285377 | 34922 | 0.341275 |
St. Martin Parish, Louisiana | 250 | 0.284196 | 52343 | 0.307224 |
St. Francis County, Arkansas | 251 | 0.283225 | 28089 | 0.519064 |
Panola County, Mississippi | 252 | 0.279903 | 34675 | 0.494650 |
Decatur County, Georgia | 253 | 0.279273 | 27815 | 0.416394 |
Jackson County, Florida | 254 | 0.277358 | 49589 | 0.261913 |
Columbus County, North Carolina | 255 | 0.277013 | 57612 | 0.305284 |
Nash County, North Carolina | 256 | 0.276561 | 95545 | 0.370632 |
Kent County, Delaware | 257 | 0.274552 | 162785 | 0.239721 |
Newberry County, South Carolina | 258 | 0.270541 | 37432 | 0.294828 |
Marlboro County, South Carolina | 259 | 0.270430 | 28750 | 0.507096 |
Barbour County, Alabama | 260 | 0.269443 | 27469 | 0.460337 |
Grady County, Georgia | 261 | 0.268071 | 25068 | 0.290769 |
Liberty County, Georgia | 262 | 0.267219 | 64663 | 0.416745 |
Dorchester County, South Carolina | 263 | 0.264107 | 136836 | 0.251893 |
Pike County, Alabama | 264 | 0.263323 | 32750 | 0.363817 |
Bradford County, Florida | 265 | 0.262607 | 28404 | 0.206168 |
Granville County, North Carolina | 266 | 0.261567 | 59666 | 0.326065 |
Newton County, Mississippi | 267 | 0.260063 | 21687 | 0.308203 |
Dinwiddie County, Virginia | 268 | 0.258897 | 27926 | 0.332307 |
Tate County, Mississippi | 269 | 0.258792 | 28580 | 0.307733 |
Martin County, North Carolina | 270 | 0.258431 | 24298 | 0.432011 |
Accomack County, Virginia | 271 | 0.256905 | 33454 | 0.287559 |
Pasquotank County, North Carolina | 272 | 0.256133 | 40551 | 0.386082 |
Crisp County, Georgia | 273 | 0.256125 | 23460 | 0.435806 |
Isle of Wight County, Virginia | 274 | 0.254947 | 35240 | 0.248751 |
Fayette County, Tennessee | 275 | 0.253915 | 38370 | 0.283138 |
Allen Parish, Louisiana | 276 | 0.252006 | 25740 | 0.201787 |
Worth County, Georgia | 277 | 0.250348 | 21746 | 0.283684 |
Mitchell County, Georgia | 278 | 0.246834 | 23510 | 0.481497 |
Scott County, Mississippi | 279 | 0.245658 | 28207 | 0.380473 |
Caswell County, North Carolina | 280 | 0.240149 | 23615 | 0.335634 |
Scotland County, North Carolina | 281 | 0.237377 | 36266 | 0.386836 |
Union County, South Carolina | 282 | 0.234053 | 28804 | 0.308499 |
Warren County, North Carolina | 283 | 0.232103 | 20860 | 0.516012 |
DeSoto County, Mississippi | 284 | 0.230644 | 161536 | 0.202252 |
Kershaw County, South Carolina | 285 | 0.229710 | 61583 | 0.252618 |
Anson County, North Carolina | 286 | 0.228731 | 26699 | 0.485711 |
Houston County, Georgia | 287 | 0.226942 | 140699 | 0.285340 |
Baldwin County, Georgia | 288 | 0.226178 | 46378 | 0.416900 |
Mecklenburg County, Virginia | 289 | 0.226062 | 32548 | 0.367703 |
Ashley County, Arkansas | 290 | 0.225847 | 21811 | 0.257347 |
Bulloch County, Georgia | 291 | 0.223243 | 70360 | 0.277572 |
Toombs County, Georgia | 292 | 0.222322 | 27270 | 0.250312 |
Halifax County, Virginia | 293 | 0.221528 | 36140 | 0.373907 |
Chesterfield County, South Carolina | 294 | 0.215468 | 46462 | 0.326611 |
Henry County, Virginia | 295 | 0.214924 | 53971 | 0.217710 |
Burke County, Georgia | 296 | 0.213276 | 23242 | 0.498580 |
Lafayette County, Mississippi | 297 | 0.212689 | 47586 | 0.242929 |
Marengo County, Alabama | 298 | 0.211436 | 20909 | 0.522550 |
Butts County, Georgia | 299 | 0.210450 | 23671 | 0.286131 |
Colleton County, South Carolina | 300 | 0.210325 | 38665 | 0.399328 |
Oktibbeha County, Mississippi | 301 | 0.206313 | 47486 | 0.368824 |
Dillon County, South Carolina | 302 | 0.203823 | 31733 | 0.469511 |
Pittsylvania County, Virginia | 303 | 0.201908 | 63318 | 0.217853 |
Iberville Parish, Louisiana | 304 | 0.199493 | 33386 | 0.486431 |
Sampson County, North Carolina | 305 | 0.199055 | 63408 | 0.267521 |
Prince Edward County, Virginia | 306 | 0.193743 | 23017 | 0.341704 |
Hampton County, South Carolina | 307 | 0.192986 | 20987 | 0.537666 |
Bertie County, North Carolina | 308 | 0.186542 | 21035 | 0.629760 |
Marion County, South Carolina | 309 | 0.179006 | 33038 | 0.566348 |
Walker County, Texas | 310 | 0.172525 | 67447 | 0.226296 |
Emanuel County, Georgia | 311 | 0.171007 | 22600 | 0.336549 |
Clarke County, Alabama | 312 | 0.160138 | 25768 | 0.438916 |
East Feliciana Parish, Louisiana | 313 | 0.159191 | 20252 | 0.451462 |
Hoke County, North Carolina | 314 | 0.155241 | 47368 | 0.342425 |
Meriwether County, Georgia | 315 | 0.147888 | 21966 | 0.401666 |
Tattnall County, Georgia | 316 | 0.146719 | 25023 | 0.285298 |
Clay County, Mississippi | 317 | 0.145219 | 20633 | 0.587554 |
Simpson County, Mississippi | 318 | 0.143515 | 27476 | 0.352053 |
Greene County, North Carolina | 319 | 0.139963 | 21386 | 0.369681 |
Washington County, Georgia | 320 | 0.138824 | 21092 | 0.530865 |
Fairfield County, South Carolina | 321 | 0.136566 | 23804 | 0.603764 |
Caroline County, Virginia | 322 | 0.128535 | 28510 | 0.295861 |
Jasper County, South Carolina | 323 | 0.121012 | 24792 | 0.451033 |
Dodge County, Georgia | 324 | 0.106523 | 21509 | 0.299967 |
Hertford County, North Carolina | 325 | 0.098368 | 24525 | 0.598614 |
def get_p_tracts_within_x_of_average(df, band=0.1):
n = len(df)
avg = df["black_pop"].sum() * 1. / df["total_pop"].sum()
within_range = df[(avg - (df["black_pop"] * 1. / df["total_pop"])).apply(abs) <= band]
return len(within_range) * 1.0 / n
Proportion of St. Louis County residents that are black:
round(stl["black_pop"].sum() * 1. / stl["total_pop"].sum(), 3)
0.231
Proportion of St. Louis County tracts that fall within 10 percentage points of that average:
round(get_p_tracts_within_x_of_average(stl, 0.1), 3)
0.141
def get_p_black_pop_in_segregated(tracts, threshold=0.8):
meets_threshold = tracts[(tracts["black_pop"] * 1.0 / tracts["total_pop"]) >= threshold]
return meets_threshold["black_pop"].sum() * 1.0 / tracts["black_pop"].sum()
Proportion of black population in St. Louis County that lives in tracts that are at least 80% black:
round(get_p_black_pop_in_segregated(stl), 3)
0.411
Proportion of black population, nationwide, that lives in tracts that are at least 80% black:
round(get_p_black_pop_in_segregated(joined), 3)
0.208
def get_demography(df, grouper):
grouped = df.groupby(grouper)
return pd.DataFrame({
"n_occupied_units": grouped["n_occupied_units"].sum(),
"p_owner_occupied": grouped["n_owner_occupied_units"].sum() * 1.0 / \
grouped["n_occupied_units"].sum(),
"p_renter_occupied": df["n_renter_occupied_units"].sum() * 1.0 / \
grouped["n_occupied_units"].sum(),
"p_unemployed": 1 - (grouped["n_employed"].sum() * 1.0 / \
grouped["n_labor_force"].sum()),
"p_poverty": grouped["n_below_poverty_level"].sum() * 1.0 / \
grouped["n_poverty_universe"].sum()
})
Comparing economic indicators several economic indicators bewteen tracts that are 80% black ("True") vs. other tracts ("False"):
demography = get_demography(stl, (stl["black_pop"] * 1.0 / stl["total_pop"]) >= 0.8)
demography.applymap(lambda x: round(x, 3))
n_occupied_units | p_owner_occupied | p_poverty | p_renter_occupied | p_unemployed | |
---|---|---|---|---|---|
False | 362710 | 0.730 | 0.089 | 0.319 | 0.073 |
True | 41441 | 0.578 | 0.245 | 2.788 | 0.190 |
import matplotlib as mpl
import mplstyle
import mplstyle.styles.simple
%matplotlib inline
mplstyle.set(mplstyle.styles.simple)
mplstyle.set({
"figure.figsize": (8, 6)
})
x_tick_labels = [ "Highly Segregated Tracts", "Other Tracts" ]
def style_axis(ax, labels):
ax.xaxis.grid(False)
ax.set_xticks(range(len(labels)))
ax.set_xticklabels(labels, rotation=0, fontsize="xx-large")#, fontweight="bold")
ax.set_yticklabels([ "{0:.0f}%".format(y * 100) for y in ax.get_yticks() ])
mpl.pyplot.tight_layout()
def make_chart(variable, title):
mpl.pyplot.bar(left=[0,1],
height=(variable[True], variable[False]),
align="center",
width=0.6,
color="red",
alpha=0.8)
ax = mpl.pyplot.axes()
style_axis(ax, x_tick_labels)
ax.set_title(title, fontsize="xx-large")
return ax
ax = make_chart(demography["p_poverty"], "Population Below Poverty Level (St. Louis County, 2012)\n")
ax = make_chart(demography["p_unemployed"], "Percent Unemployment (St. Louis County, 2012)\n")
ax = make_chart(demography["p_owner_occupied"], "Households Owning Home (St. Louis County, 2012))\n")
mpl.pyplot.bar(left=[0,1],
height=(get_p_black_pop_in_segregated(joined), get_p_black_pop_in_segregated(stl)),
align="center",
width=0.6,
color="red",
alpha=0.8)
ax = mpl.pyplot.axes()
style_axis(ax, [ "Nationwide", "St. Louis County" ])
ax.set_title("Percentage of Black Residents Who Live In \nCensus Tracts That Are At Least 80% Black\n", fontsize="xx-large")
pass