How to use http://www.census.gov API to pull data
Asked Answered
G

2

6

Am trying to query data from http://www.census.gov, using their API I want to get the population of a particular city in the US, by using the city name and the US state code.

Given that I already have the key, what other parameters do I add in the URL below, so that I can get the population.

http://api.census.gov/data/2010/sf1?key=<my key>

any assistance will be greatly appreciated

Gelid answered 5/11, 2013 at 7:29 Comment(5)
You probably shouldn't be exposing your key on a public site like StackOverflow or you may be violating census.gov's terms of use.Darya
Also have you tried looking at examples and documentation here? census.gov/developersDarya
@Darya The key in his query URI is the key used in the census developers examples. Either he has lightly perused the documentation or he is serving up a secondhand bowl of copypasta... At least he isn't exposing himself in public...Ascot
@Ascot ah right, didn't know about the example keyDarya
@Darya i have use the key that is found here census.gov/developers so as to not expose the one that i acquired. thanks for the observationGelid
A
6

Judging from your query URI, you wish to access population data from the 2010 Census Summary File. You would add GET paramaters of get and for to your query. Example:

http://api.census.gov/data/2010/sf1?key=b48301d897146e8f8efd9bef3c6eb1fcb864cf&get=P0010001&for=state:06

The population table as given in the get parameter are identified with a "P" and you can use the for parameter to further narrow down your scope. Examples of valid criteria formatted as URIs can be found here...

EDIT: It seems that for a finer grained search such as cities, you're going to need to use the governments cumbersome FIPS (Federal Information Processing Standard) codes (after converting lat/lon regions to their coding system)... I've found this resource that should be helpful, specifically points 5 thru 7, but it seems mega complex...

Another alternative I found is the USA Today census API, it seems that they mirror the data from the census and they do have available endpoints with data granularity at the city level... Check it out here...

Ascot answered 5/11, 2013 at 8:10 Comment(6)
yes, the url above takes me to the type of documentation am looking for however this particular documentation does not have an example of how to get the population of a city. example getting the population of Adamsville in the state Alabama (AL). FYI i have a database table that has the city names and the state code. i want to create a new column which will save the city populations. at this point any documentation on how to handle the "city" parameter will be very appreciated.Gelid
@user2825816 Check the edits... For some reason the government doesn't consider cities to be an adequate level of demarcation. I suppose the census is taken on a county level, so it would probably require complex queries on their end to make it directly available and they opted to 'pass the buck' instead...Ascot
given the following url (census.gov/2010census/popmap/ipmtext.php?fl=01:0600394) one can get info on different cities/towns by changing the last set of numbers after the colon : Example census.gov/2010census/popmap/ipmtext.php?fl=01:0100124 census.gov/2010census/popmap/ipmtext.php?fl=01:0600394Gelid
census.gov/2010census/popmap/ipmtext.php?fl=01:0100820 the only problem is getting documentation on the numbers if any documentation exists at all. there is also the option of using a bot to crawl the URL and pull the relevant data.Gelid
Thanks for pointing to my link. The census API is 'mega complex' but I think that is due to the complexity of the data it points to.Osteitis
@Osteitis No problem. Yeah, large caches of demographic data are pretty forced to be complex by nature.Ascot
G
1

no need to use API the data is available in CSV here http://www.census.gov/popest/data/cities/totals/2012/SUB-EST2012.html

Gelid answered 6/11, 2013 at 8:43 Comment(1)
dead link; please fix.Algorithm

© 2022 - 2024 — McMap. All rights reserved.