By: Mike Johnson Jr
Date Created: Feb. 17, 2020, 4:20 a.m.

I had the question "how many black people actually live in the hood?" I Googled, no answer. So I downloaded census data and decided to find the answer myself, and added some more interesting data. Let me know if my math is wrong somewhere.

Data Source: https://www.kaggle.com/muonneutrino/us-census-demographic-data

Code:

import pandas as pd
import json

incomes = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000]

df = pd.read_csv('acs2017_census_tract_data.csv') # or df = pd.read_csv('acs2017_county_data.csv')

total_pop_all = df['TotalPop'].sum()

races = {
'Black': {},
'White': {},
'Hispanic': {},
'Asian': {},
'Native': {},
'Pacific': {},
}

for inc in incomes:
for race in races:
total_pop_of_race = df[race] * df['TotalPop'] / 100
#lic is low income county
lic = df[df['Income'] < inc]
lic['race_low_income_total_pop'] = lic[race] * lic['TotalPop'] / 100
races[race][inc] = lic['race_low_income_total_pop'].sum() / total_pop_of_race.sum()

print(json.dumps(races))