US Census API now available
census.gov
census.gov
For ease of exploring new ideas it would be super handy to be able to push it all into a hadoop cluster on aws or some such nonsense.
EDIT: Found it! Hopefully... http://www2.census.gov/census_2010/04-Summary_File_1/
Right now, I download a zip file containing a bunch of csv files. Then:
$ unzip filename.zip
$ ipython -pylab
import pandas
sum_data = read_csv("atussum_2011.dat")
adult_indices = where(logical_and(sum_data[:]['TEAGE'] >= 18, sum_data[:]['TEAGE'] <= 65))[0]
...
How does an API benefit me? Having done plenty of work with json APIs, I can't see how it could possibly be easier than this. $ scp census_data.csv admin@my_postgres_server:/tmp/census_data.csv
$ ssh admin@my_postgres_server
$ psql
# CREATE TABLE census_data ... ;
# COPY census_data FROM '/tmp/census_data.csv' (DELIMITER ',');
# CREATE INDEX idx_census_zipcode ON census_data(zipcode);
To do the actual search: conn = psycopg2.connect("dbname=census_data user=postgres")
cur = conn.cursor()
cur.execute("SELECT count(id) FROM census_data WHERE zipcode='%s';", (zipcode, ))
return cur.fetchone()
What advantage does http/json have over this?(Yes, I realize I'm missing GROUP BY's.)
[edit: I don't mean to be negative about government transparency AT ALL. I'm only criticizing the particular technical choice here - for small structured data sets, a bunch of csv's in a zip file is the clear winner. Pandas/excel/etc >> json over http for ad-hoc work, and postgres >> json over http for interactive queries (or ad-hoc work).]
With a few indices and maybe even a materialized view (or even pruning data you don't need), you can answer most queries so fast that latency between linode and the census > query time.
I know munging csv's and writing sql isn't as sexy as JSON APIs or mongodb, but sometimes the simple solutions are the right ones.
You forgot about unzipping. The total is 13.49 GB zipped, or 133.4 GB unzipped. [0]
[0] http://www2.census.gov/census_2010/04-Summary_File_1/Califor...
A bunch of news apps guys under the aegis of Investigative Reporters & Editors put together an alternative API that's much easier to work with:
http://usa.ipums.org/usa/ http://usa.ipums.org/usa/doc.shtml