Finding Census Block for all of your address

I've been looking at estimating the rational and socio-economic makeup of patrons. 

Once one has geocoded the addresses in your database the next challenge is to connect this information to the census data.  You can do this by Zipcode by a Zipcode in major urban areas can be a large place with lots of different people.  The Census block is a lot more fine-grained information.  I've discovered that the fcc (Federal Communication Commission provides a latitude to longitude services here in the US.  You can query this via a fairly simple API.

Here is some Python 2.x code that will get this information.

import requests
import pandas as pd

# Helper function to get the blocks
def get_block(lat, lon):
data = {
'format': 'json',
'showall': 'true',
'latitude': lat,
'longitude': lon
}
r = requests.get('geo.fcc.gov/.../find', params=data)
if r.status_code == 200:
return r.json()
else:
return None

# The Latatude and Longatude of the Washington, Monument in DC
get_block(38.889484,-77.035278)

This produces this JSON.

{u'Block': {u'FIPS': u'110010062021098',
  u'bbox': [-77.035537, 38.889353, -77.035085, 38.889714]},
 u'County': {u'FIPS': u'11001', u'name': u'District of Columbia'},
 u'State': {u'FIPS': u'11', u'code': u'DC', u'name': u'District of Columbia'},
 u'executionTime': u'0',
 u'status': u'OK'}

Hope this help someone.  Let me know if this does you some good.

--Tom

P.S. the description of the API can be found here.  https://geo.fcc.gov/api/census/.

This is based on a design by the team at Dataiku see here. dataiku.teachable.com/.../864705