Skip to main content

A small example package

Project description

CensusAPI

Implementation of US Census API calls in form of a python library.

CensusAPI allows to output an augmented geojson file containing census information at the US census tract block level given a geojson file in the US.

Requirements

Key

Obtain a key from http://api.census.gov/data/key_signup.html to acess the Census dataset and place it in a .env' file: secretKey = Yourkey

Install

See the requirements.txt for all the packages.

  • census==0.8.19
  • censusgeocode==0.5.2
  • geopandas==0.9.0
  • pandas==1.5.1

Usage

Defined in censusgf.py.

add_census_to_geojson: Returns a geojson with columns containing Census Tract Level Data regarding building tract level ownership, population and income.

Parameters:

  • in_pth: str. The file location of the geojson building file.
  • out_pth: str. The file location in which to save the augmented file.
  • key: str. The 40 digit text string. Can be obtained from the US Census site.
  • census_variables: tuple[str]. Default = None. An optional tuple of strings identifying ACS 5 Census variables to augment the dataframe. If custom_variables is not specified the function will return an augmented geojson with default columns.

add_census_to_geojson_df: Returns a geojson with additional columns containing Census Tract Level Data regarding building tract level ownership, population and income.

Parameters:

  • df: GeoDataFrame. The input geodataframe.
  • key: str. The 40 digit text string. Can be obtained from the US Census site.
  • census_variables: tuple[str]. Default = None. An optional tuple of strings identifying ACS 5 Census variables to augment the dataframe. If custom_variables is not specified the function will return an augmented geojson with default columns.

Default Census Variables:

Default variables used to augment the geojson are specified below. They are taken from the ACS 5, 2020 dataset. Default variables can be found in the Detailed Tables:

Census Variable Readable Column Name Variable Description
B01003_001E TotPop Total Population
B25003_003E RentOcc Renter occupied
B25003_002E OwnOcc Owner Occupied
B25121_001E Income Household income in the past 12 months (in 2020 inflation-adjusted dollars) by value
B25121_002E less10k Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!Less than $10,000
B25121_017E 10to20k Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$10,000 to $19,999
B25121_032E 20to35k Estimate!!Total:!!Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$20,000 to $34,999
B25121_047E 35to50k Estimate!!Total:!!Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$35,000 to $49,999
B25121_062E 50to75k Estimate!!Total:!!Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$50,000 to $74,999
B25121_077E 75to100k Estimate!!Total:!!Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$75,000 to $99,999
B25121_092E more100k Estimate!!Total:!!Household income the past 12 months (in 2020 inflation-adjusted dollars) --!!$100,000 or more

Example

Example can be found in example.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geocensusapi-0.0.2.tar.gz (732.1 kB view hashes)

Uploaded Source

Built Distribution

geocensusapi-0.0.2-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page