First, get yourself a US Census.gov API key. Store this key in the same directory as main.py as api_key.toml
based on the format of the example_key_api.toml
. Note the link requires a US based IP address, VPNs will work.
python3 -m venv .virtualenv/
Create Python Virtual Environmentsource .virtualenv/bin/activate
activate virtual environmentpip install -r requirements.txt
Install Requirements
python main.py -s CA -p 'Los Angeles city'
-s
required: State abbreviation-p
requied: Place name, must be exact, will output list of examples. SinceLos Angeles
matches mutliple place names, it will prompt you to chooseLos Angeles city
orLos Angeles county
This is the main census data on most place pages. This should not be completely copied unless the page does not yet have any census table. Best practice is to use the part you need, which often is the 2020 and estimate sections.
Text of example:
{{US Census population
|2000= 3694820
|2010= 3792621
|2020= 3898747
|estyear=2022
|estimate=3881041
|estref=<ref name="acs2022est">{{cite web|url=https://data.census.gov/table?g=1600000US0644000&y=2022|title=ACS Survey Population Estimate 2022}}</ref>
|footnote=US Census<ref name="DecennialCensus2020">{{cite web|url=https://data.census.gov/table/DECENNIALPL2020?g=160XX00US0644000|title=Census of Population and Housing|publisher=Census.gov}}</ref>
This table shows changes in various populations over the past 3 Census:
Text of example:
{| class="wikitable sortable collapsible" style="font-size: 90%;"
|+ Race and Ethnicity
! Racial and ethnic composition
! 2000<ref name=datacensus2000p2>{{cite web|url=https://data.census.gov/table?g=1600000US0644000&y=2000&d=DEC+Redistricting+Data+(PL+94-171)&tid=DECENNIALPL2000.PL002|publisher=US Census Bureau|title=2000: DEC Redistricting Data (PL 94-171)}}</ref>
! 2010<ref name=datacensus2010p2>{{cite web|url=https://data.census.gov/table?g=1600000US0644000&y=2010&d=DEC+Redistricting+Data+(PL+94-171)&tid=DECENNIALPL2010.P2|publisher=US Census Bureau|title=2010: DEC Redistricting Data (PL 94-171)}}</ref>
! 2020<ref name=datacensus2020p2>{{cite web|url=https://data.census.gov/table?g=1600000US0644000&y=2020&d=DEC+Redistricting+Data+(PL+94-171)&tid=DECENNIALPL2020.P2|publisher=US Census Bureau|title=2020: DEC Redistricting Data (PL 94-171)}}</ref>
|-
! [[Hispanic and Latino Americans|Hispanic or Latino (of any race)]]
| 46.53%
| 48.48%
| 46.94%
|-
! [[Non-Hispanic whites|White (non-Hispanic)]]
| 29.75%
| 28.66%
| 28.88%
|-
! [[Asian American|Asian (non-Hispanic)]]
| 9.87%
| 11.08%
| 11.66%
|-
! [[African American|Black or African American (non-Hispanic)]]
| 10.88%
| 9.16%
| 8.27%
|-
! [[Multiracial American|Two or more races (non-Hispanic)]]
| 2.36%
| 2.01%
| 3.28%
|-
! Other (non-Hispanic)
| 0.25%
| 0.32%
| 0.68%
|-
! [[Native Americans in the United States|Native American (non-Hispanic)]]
| 0.24%
| 0.17%
| 0.17%
|-
! [[Pacific Islander Americans|Pacific Islander (non-Hispanic)]]
| 0.12%
| 0.11%
| 0.12%
|}