pycensus.census.countries.usa.utils¶
Small stateless helpers shared by every US census source module.
Technical aspects
GEOID columns are named inconsistently across TIGER/Line vintages
(GEOID, GEOID20, GEOID10, ...); :func:pick_geoid_column
picks the best match deterministically. Every pygris call this package
makes uses cache=False -- persistence is pyCensus' own parquet
cache (:mod:pycensus.cache), not pygris' internal shapefile cache.
pick_geoid_column(columns)
¶
Pick the most specific GEOID* column present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Iterable[str]
|
Candidate column names. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The best-matching column name, or |
Optional[str]
|
GEOID column. |
state_abbr(state)
¶
Normalize a state name, abbreviation, or FIPS code to its USPS abbreviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
State name, abbreviation, or FIPS code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Two-letter USPS state abbreviation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
state_fips(state)
¶
Normalize a state name, abbreviation, or FIPS code to its FIPS code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
State name, abbreviation, or FIPS code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Two-digit FIPS code. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |