Skip to content

Instantly share code, notes, and snippets.

After some discussion about how a map showing that half of US income can be attributed to the major metro areas, I wanted to see if I could work out how public assistance is distributed.

The American Community Survey has a table, B19067, Aggregate Public Assistance Income for Households, which tells the total amount of dollars in public assistance income that go to each geography. As you might guess, the biggest metro areas have the most dollars.

So I downloaded some CSVs from Census Reporter for all CBSA (metro/micropolitan) areas in the US:

@JoeGermuska
JoeGermuska / counties_with_low_income_tracts.sql
Created January 5, 2014 22:34
Low earning counties: find all tracts in the US where no one earns more than $50K a year, and list the counties they are contained by and the median income for that county. Source: Table B19001 'Household Income in the Past 12 Months (In 2012 Inflation-adjusted Dollars)' American Community Survey as loaded in Census Reporter Postgres database (h…
select c.geoid, c.name, d2.B19013001, count(*)
from acs2012_5yr.geoheader c,
acs2012_5yr.geoheader g,
acs2012_5yr.B19001 d,
acs2012_5yr.B19013 d2
where B19001011 = 0
and B19001012 = 0
and B19001013 = 0
and B19001014 = 0
and B19001015 = 0
@JoeGermuska
JoeGermuska / poverty_rate.html
Last active January 2, 2016 07:18
Find geographies with a poverty rate of greater than 40% with less than 10% derived MOE (excluding Puerto Rico) -- see https://www.pivotaltracker.com/story/show/63255358 I can't remember what it takes to get HTML rendered in gist, so I included the same data as text also.
<table border="1">
<tr>
<th align="center">geoid</th>
<th align="center">rate</th>
<th align="center">moe</th>
<th align="center">b17001001</th>
<th align="center">b17001002</th>
<th align="center">b17001001_moe</th>
<th align="center">b17001002_moe</th>
</tr>
@JoeGermuska
JoeGermuska / count_impacted_tracts output
Last active December 27, 2015 02:19
Finding fragments of census tracts that are not in a place (in this case, Chicago) when other parts of the tract are in that place. Working against Census Reporter SQL schema as in http://censusreporter.tumblr.com/post/55886690087/using-census-data-in-postgresql
state | county | tract | count
-------+--------+--------+-------
17 | 031 | 010400 | 1
17 | 031 | 020702 | 1
17 | 031 | 030101 | 1
17 | 031 | 030102 | 1
17 | 031 | 030103 | 1
17 | 031 | 030104 | 1
17 | 031 | 030601 | 1
17 | 031 | 030604 | 1
Demographics
age
race
seniors
sex (not gender: http://factfinder2.census.gov/help/en/glossary/g/gender.htm)
Social
ancestry
citizenship
disability
education
@JoeGermuska
JoeGermuska / Only tables with 0.5 columsn
Last active December 20, 2015 21:09
non-data columns from ACS 2011-1year
Table ID,Line Number Decimal M Lines,Long Table Title
B01002,,MEDIAN AGE BY SEX
B01002,0.5,Median age --
B01002A,,MEDIAN AGE BY SEX (WHITE ALONE)
B01002A,0.5,Median age --
B01002B,,MEDIAN AGE BY SEX (BLACK OR AFRICAN AMERICAN ALONE)
B01002B,0.5,Median age --
B01002C,,MEDIAN AGE BY SEX (AMERICAN INDIAN AND ALASKA NATIVE)
B01002C,0.5,Median age --
B01002D,,MEDIAN AGE BY SEX (ASIAN ALONE)
@JoeGermuska
JoeGermuska / All ACS 2011-1 first column labels by count, excluding those with Total
Last active December 20, 2015 20:59
All first column labels from Census, with count of occurrences. csvgrep -c 4 -r '^1$' acs2011_1yr_Sequence_Number_and_Table_Number_Lookup.csv | csvgrep -c 8 -r '^Total' -i | csvcut -c 8 | sort | uniq -c
1 "Aggregate interest, dividends, or net rental income in the past 12 months (in 2011 inflation-adjusted dollars)"
1 "Aggregate number of vehicles (car, truck, or van) used in commuting:"
1 Aggregate Social Security income in the past 12 months (in 2011 inflation-adjusted dollars)
1 Aggregate Supplemental Security Income (SSI) in the past 12 months (in 2011 inflation-adjusted dollars)
1 Aggregate contract rent
1 Aggregate earnings in the past 12 months (in 2011 inflation-adjusted dollars)
1 Aggregate earnings in the past 12 months (in 2011 inflation-adjusted dollars):
1 Aggregate family income in the past 12 months (in 2011 inflation-adjusted dollars)
3 Aggregate family income in the past 12 months (in 2011 inflation-adjusted dollars):
1 Aggregate gross rent
@JoeGermuska
JoeGermuska / millennium_park_2013.py
Last active December 16, 2015 21:29
A pair of simple python scripts to produce ICS files of free music in Chicago for the Summer of 2013, and the ICS files they produced. You should be able to "subscribe" to these calendars in MacOS Calendar or Google Calendar using the "raw" URL for the ICS files below, or more simply http://j.mp/millpark2013 and http://j.mp/summerdance2013 The M…
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from icalendar import Calendar, Event
from datetime import timedelta
from dateutil.parser import parse
from dateutil.tz import tzlocal
from pyquery import PyQuery as pq
from urlparse import urljoin
urls = {
@JoeGermuska
JoeGermuska / gist:2514658
Created April 28, 2012 00:34
The Chicago Tribune is seeking a CAR journalist…
The Chicago Tribune is seeking a CAR journalist who can serve a 2-year
residency for the newsroom. The candidate for this Computer Assisted
Reporting position should have proven watchdog skills and experience
with every facet of story development, from filing FOIA requests to
finishing a polished draft of a newspaper story and its digital
package. Clips should show proven results of this kind of work.
A key part of the job is to work with suburban reporters assigned to
specific towns to tell stories that can be told only by those with
command of hard data. This journalist also will be looking
@JoeGermuska
JoeGermuska / ranker.py
Created April 18, 2012 15:20
Example of how to convert a csv file to a table of ranked headers for each row
#!/usr/bin/env python
import csv, json
from collections import defaultdict
r = csv.reader(open("data.csv"))
headers = r.next()
countries = headers[1:]
out_rows = []
for row in r:
area = row[0]
out_row = [area]