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

12,128

Solution 1

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...

Solution 2

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

Share:
12,128

Related videos on Youtube

hyena
Author by

hyena

android developer as my career and my hobby. On a typical weekend, i will be over engineering one of my apps, this help improve my understanding on how to effectively apply clean architecture reactive programing using observables, with fully immutable models, dagger injection and minimal side effects. All this is done under the a very strong influence of "testable code instinct".

Updated on September 16, 2022

Comments

  • hyena
    hyena over 1 year

    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

    • jingtao
      jingtao over 10 years
      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.
    • Tonithy
      Tonithy over 10 years
      @jingtao 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...
  • hyena
    hyena over 10 years
    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.
  • Tonithy
    Tonithy over 10 years
    @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...
  • hyena
    hyena over 10 years
    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:0600394
  • hyena
    hyena over 10 years
    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.
  • mooreds
    mooreds over 10 years
    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.
  • Tonithy
    Tonithy over 7 years
    @mooreds No problem. Yeah, large caches of demographic data are pretty forced to be complex by nature.
  • Mox
    Mox over 6 years
    dead link; please fix.