censusdis.states
This module defines state FIPS codes and some utilities for using them.
The US Census identifies states by their FIPS Codes, which are two-digit numeric strings. For convenience, we define identifiers for them.
Each identifier
has a name of the form STATE_XX where XX is the two
letter abbreviation for the state. For example, NJ
is the two letter abbreviation for New Jersey, and the
Census state identifier for New Jersey is 34, so:
import censusdis.states as cds
state = cds.STATE_NJ
would set the value of state to the string “34”. We can use these values in any of the APIs in censusdis that take a state.
There is also a dictionary whose keys are the state FIPS codes and whose values are strings naming the states. It is typically used when we want a more human-friendly name for each state. As in:
import censusdis.states as cds
state = cds.STATE_CA
print(
f"The name of the state with ID '{state}' "
f"is '{cds.STATE_NAMES_FROM_IDS[state]}'."
)
Finally, there is a list of all states. It is often useful if we want to perform an operation on all states. For example:
import censusdis.states as cds
for state in cds.ALL_STATES:
do_something_with_a_state(state)
There is also a list that includes all states and the
District of Columbia. It is called cds.ALL_STATES_AND_DC.
- censusdis.states.ALL_STATES = ['01', '02', '04', '05', '06', '08', '09', '10', '12', '13', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '27', '28', '26', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '44', '45', '46', '47', '48', '49', '50', '51', '53', '54', '55', '56', '72']
All the state FIPS codes.
Includes all 50 states, but not DC.
Typically used to iterate over the states, as in:
from censusdis.states import ALL_STATES for state in ALL_STATES: process_state(state)
- censusdis.states.ALL_STATES_AND_DC = ['01', '02', '04', '05', '06', '08', '09', '11', '10', '12', '13', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '27', '28', '26', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '44', '45', '46', '47', '48', '49', '50', '51', '53', '54', '55', '56']
All the state FIPS codes and DC.
Includes all 50 states and DC.
Typically used to iterate over the states, as in:
from censusdis.states import ALL_STATES_AND_DC for state in ALL_STATES_AND_DC: process_state(state)
- censusdis.states.ALL_STATES_DC_AND_PR = ['01', '02', '04', '05', '06', '08', '09', '11', '10', '12', '13', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '27', '28', '26', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '44', '45', '46', '47', '48', '49', '50', '51', '53', '54', '55', '56', '72']
All the state FIPS codes and DC and PR.
Includes all 50 states, DC and PR.
Typically used to iterate over the states, as in:
from censusdis.states import ALL_STATES_DC_AND_PR for state in ALL_STATES_DC_AND_PR: process_state(state)
- censusdis.states.STATE_AK = '02'
Alaska
- censusdis.states.STATE_AL = '01'
Alabama
- censusdis.states.STATE_AR = '05'
Arkansas
- censusdis.states.STATE_AZ = '04'
Arizona
- censusdis.states.STATE_CA = '06'
California
- censusdis.states.STATE_CO = '08'
Colorado
- censusdis.states.STATE_CT = '09'
Connecticut
- censusdis.states.STATE_DC = '11'
District of Columbia
- censusdis.states.STATE_DE = '10'
Delaware
- censusdis.states.STATE_FL = '12'
Florida
- censusdis.states.STATE_GA = '13'
Georgia
- censusdis.states.STATE_HI = '15'
Hawaii
- censusdis.states.STATE_IA = '19'
Iowa
- censusdis.states.STATE_ID = '16'
Idaho
- censusdis.states.STATE_IL = '17'
Illinois
- censusdis.states.STATE_IN = '18'
Indiana
- censusdis.states.STATE_KS = '20'
Kansas
- censusdis.states.STATE_KY = '21'
Kentucky
- censusdis.states.STATE_LA = '22'
Louisiana
- censusdis.states.STATE_MA = '25'
Massachusetts
- censusdis.states.STATE_MD = '24'
Maryland
- censusdis.states.STATE_ME = '23'
Maine
- censusdis.states.STATE_MI = '26'
Michigan
- censusdis.states.STATE_MN = '27'
Minnesota
- censusdis.states.STATE_MO = '29'
Missouri
- censusdis.states.STATE_MS = '28'
Mississippi
- censusdis.states.STATE_MT = '30'
Montana
- censusdis.states.STATE_NAMES_FROM_IDS = {'01': 'Alabama', '02': 'Alaska', '04': 'Arizona', '05': 'Arkansas', '06': 'California', '08': 'Colorado', '09': 'Connecticut', '10': 'Delaware', '11': 'District of Columbia', '12': 'Florida', '13': 'Georgia', '15': 'Hawaii', '16': 'Idaho', '17': 'Illinois', '18': 'Indiana', '19': 'Iowa', '20': 'Kansas', '21': 'Kentucky', '22': 'Louisiana', '23': 'Maine', '24': 'Maryland', '25': 'Massachusetts', '26': 'Michigan', '27': 'Minnesota', '28': 'Mississippi', '29': 'Missouri', '30': 'Montana', '31': 'Nebraska', '32': 'Nevada', '33': 'New Hampshire', '34': 'New Jersey', '35': 'New Mexico', '36': 'New York', '37': 'North Carolina', '38': 'North Dakota', '39': 'Ohio', '40': 'Oklahoma', '41': 'Oregon', '42': 'Pennsylvania', '44': 'Rhode Island', '45': 'South Carolina', '46': 'South Dakota', '47': 'Tennessee', '48': 'Texas', '49': 'Utah', '50': 'Vermont', '51': 'Virginia', '53': 'Washington', '54': 'West Virginia', '55': 'Wisconsin', '56': 'Wyoming', '72': 'Puerto Rico'}
The names of each state, indexed by FIPS code.
For example,
STATE_NAMES_FROM_IDS[STATE_NJ]is"New Jersey".
- censusdis.states.STATE_NC = '37'
North Carolina
- censusdis.states.STATE_ND = '38'
North Dakota
- censusdis.states.STATE_NE = '31'
Nebraska
- censusdis.states.STATE_NH = '33'
New Hampshire
- censusdis.states.STATE_NJ = '34'
New Jersey–The Garden State
- censusdis.states.STATE_NM = '35'
New Mexico
- censusdis.states.STATE_NV = '32'
Nevada
- censusdis.states.STATE_NY = '36'
New York
- censusdis.states.STATE_OH = '39'
Ohio
- censusdis.states.STATE_OK = '40'
Oklahoma
- censusdis.states.STATE_OR = '41'
Oregon
- censusdis.states.STATE_PA = '42'
Pennsylvania
- censusdis.states.STATE_RI = '44'
Rhode Island
- censusdis.states.STATE_SC = '45'
South Carolina
- censusdis.states.STATE_SD = '46'
South Dakota
- censusdis.states.STATE_TN = '47'
Tennessee
- censusdis.states.STATE_TX = '48'
Texas
- censusdis.states.STATE_UT = '49'
Utah
- censusdis.states.STATE_VA = '51'
Virginia
- censusdis.states.STATE_VT = '50'
Vermont
- censusdis.states.STATE_WA = '53'
Washington
- censusdis.states.STATE_WI = '55'
Wisconsin
- censusdis.states.STATE_WV = '54'
West Virginia
- censusdis.states.STATE_WY = '56'
Wyoming
- censusdis.states.TERRITORY_PR = '72'
Puerto Rico