Git Product home page Git Product logo

bbrotsos / census-api-map Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mitchdolby/census-api-map

0.0 0.0 0.0 60.83 MB

Script that extracts data from the census API on the block group level from the ACS 5-year detailed tables

Python 95.67% C 1.35% C++ 0.44% Shell 0.01% Batchfile 0.01% HTML 0.13% JavaScript 0.01% CSS 0.01% Fortran 0.02% Smarty 0.01% XSLT 0.01% VBScript 0.01% Classic ASP 0.01% Cython 2.36%

census-api-map's Introduction

Census-API-Map

This project is a python script that requests data from the API of the United States Census Bureau, and saves the data on the state, county, tract, and block group level as a .CSV file

This markdown will show you how to navigate and run the census_api_bg.py script

First, make sure you have the python language and a code editor downloaded. I personally prefer to use anaconda and visual studio code.

After all of the programs and code are properly installed and are in your respective file directory locations, open the code which is in the "scripts" folder of this repo.

In the config.py file, you will need to replace the "INSERT_API_KEY" string with an API key string. You can request a Census API key from the Census Bureau website at census/developers.gov. On that page, there is a large button that says "request a key". Click that key, enter your credentials, and you will recieve an email with your API key. Copy and paste that key into the api_key variable in config.py

censusapi1

censusapi2

The script should be ready now. Open your command prompt terminal.

censusapi3

In your terminal, you will need to change your directory to the location where the census API code is stored; the command for this is "cd <your_directory_path>"

censusapi4

At this time the script takes four arguments: state, var, name, and overwrite, the first two being positional (required), and the second two being optional. An optional argument means that you can choose if you want to include it in the argument or not.

Enter in the command terminal "python census_api_bg.py -h" (the -h can be substituted with --help) which is the command that will show the list of arguments and what each argument entails. See the screenshot below for the descriptions of each argument.

censusapi5

For --state, you will need to input the two-letter abbreviation of the state of your choosing (i.e. 'VA' for Virginia). It also supports Washington DC ('DC') and Puerto Rico.

To find the variables you need, you will have to return to the census/developers.gov website. Under the "Available APIs" tab in the lefthand menu, click on the American Community Survey 5-year Data, and open the html of the variables list from the Detailed Tables. There you will see an exhaustive list of variables and their respective codes that you can choose from. Keep in mind that as of now this script only supports Detailed Tables, so don't choose anything from the Subject Tables, Data Profile, and Comparison Profile.

censusapi6

censusapi7

After learning the arguments, it's time to run the code

In this screenshot, I ran an example of what running the script could look like:

censusapi8

If you check your file, the data that you requested should have saved into your directory, and should now be ready for use. It should be saved into a NEW FOLDER called 'states_data'. Here is what the cleaned file should look like:

censusapi9

census-api-map's People

Contributors

mitchdolby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.