PyCensus
The pyCensus module is designed to interact with the United States Census Bureau API. It handles making the request to the api, and transforms the returned data into a pandas dataframe.
Prerequisites and Installation
This requires Python 3.7 or later to be installed.
pip install pycensus
Setup
This tool is not yet designed to be used with an API key, but that is something that could easily be added in the future.
Shell Scripts
PyCensus comes with shell scripts to parse the online API documentation and allow it to be searched easily by the user.
search all endpoints:
census-endpoints [year] [column to search]
available_columns:
- c_vintage = year
- c_dataset = Dataset identifier
- title
- description
search variables, geographies, or groups for an endpoint:
census-variables [year] [dataset]
census-geography [year] [dataset]
census-groups [year] [dataset]
This can be used to parse the variables, geography, or groups sheets available for a specific endpoint.
An example is below:
census-geography 2019 acs acs5 profile
censusData
censusData gets data from the Census Bureau api based on certain attributes given when an object is instatiated.
Input attributes:
dataset= list; The list of abbreviations for the dataset name path. This can be found by going to the https://api.census.gov/data.html page or running find-endpoint and using the value in the "Dataset Name" column.year= int; the Year that corresponds to the chosen dataset.query_dict= dict; The dict of how the query should be structured. This should include any other necessary pieces to construct the query like "for" and "in". See the examples for the chosen dataset for help with constructing a query.
Below is an exmaple of how acsData could be instantiated:
test_data = censusData(
['acs', 'acs5', 'profile'],
2019,
{
'get' : 'group(DP03)',
'in' : 'state:04',
'for' : 'county:019,007'
}
)
censusData.clean_df
This produces a pandas dataframe from the Census Bureau data and replaces the column names with names that explain what the data point is.
Input arguments:
index_col= str; The column that should be the index columnreplace_col_names= bool;Truewill replace column names with the variable names,Falsewill leave columns named with variable ID.
Returns: Pandas Dataframe MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for pyCensus 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyCensus-0.0.2.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyCensus-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.4 kB
Release files / pyCensus-0.0.2.tar.gz
| Download URL | pyCensus-0.0.2.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c748f72b55c1086fca8bdd4c148a8a9cf46a192558619effec279e40eb27c45
|
|
BLAKE2b-256 checksum How to use checksums |
fbdf416abdecb9c23d443530d991980acb9ea9eee4d7a24993333c047df5a598
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / pyCensus-0.0.2-py3-none-any.whl
| Download URL | pyCensus-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a065d623d0679210b4011ae9e81744c4902e7c0d22e25ffc745dbdd6f236a2bd
|
|
BLAKE2b-256 checksum How to use checksums |
3d338996617e77cb98d3b6d4c1bc3f9d3f9a4ec2193ed75565bf5bb0ce5d51fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Security for pyCensus 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.