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 corresponds to 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:
from censusdis import states
state = states.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:
from censusdis import states
state = states.CA
print(
f"The name of the state with ID '{state}' "
f"is '{states.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:
from censusdis import states
for state in states.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 ALL_STATES_AND_DC.
And finally, ALL_STATES_AND_DC_AND_PR includes
Puerto Rico as well.
- censusdis.states.ABBREVIATIONS_FROM_IDS = {'01': 'AL', '02': 'AK', '04': 'AZ', '05': 'AR', '06': 'CA', '08': 'CO', '09': 'CT', '10': 'DE', '11': 'DC', '12': 'FL', '13': 'GA', '15': 'HI', '16': 'ID', '17': 'IL', '18': 'IN', '19': 'IA', '20': 'KS', '21': 'KY', '22': 'LA', '23': 'ME', '24': 'MD', '25': 'MA', '26': 'MI', '27': 'MN', '28': 'MS', '29': 'MO', '30': 'MT', '31': 'NE', '32': 'NV', '33': 'NH', '34': 'NJ', '35': 'NM', '36': 'NY', '37': 'NC', '38': 'ND', '39': 'OH', '40': 'OK', '41': 'OR', '42': 'PA', '44': 'RI', '45': 'SC', '46': 'SD', '47': 'TN', '48': 'TX', '49': 'UT', '50': 'VT', '51': 'VA', '53': 'WA', '54': 'WV', '55': 'WI', '56': 'WY', '72': 'PR'}
The postal abbreviation of each state, indexed by FIPS code.
For example,
NAMES_FROM_IDS[NJ]is"NJ".
- censusdis.states.AK = '02'
Alaska
- censusdis.states.AL = '01'
Alabama
- 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.AR = '05'
Arkansas
- censusdis.states.AZ = '04'
Arizona
- censusdis.states.CA = '06'
California
- censusdis.states.CO = '08'
Colorado
- censusdis.states.CT = '09'
Connecticut
- censusdis.states.DC = '11'
District of Columbia
- censusdis.states.DE = '10'
Delaware
- censusdis.states.FL = '12'
Florida
- censusdis.states.GA = '13'
Georgia
- censusdis.states.HI = '15'
Hawaii
- censusdis.states.IA = '19'
Iowa
- censusdis.states.ID = '16'
Idaho
- censusdis.states.IDS_FROM_ABBREVIATIONS = {'AK': '02', 'AL': '01', 'AR': '05', 'AZ': '04', 'CA': '06', 'CO': '08', 'CT': '09', 'DC': '11', 'DE': '10', 'FL': '12', 'GA': '13', 'HI': '15', 'IA': '19', 'ID': '16', 'IL': '17', 'IN': '18', 'KS': '20', 'KY': '21', 'LA': '22', 'MA': '25', 'MD': '24', 'ME': '23', 'MI': '26', 'MN': '27', 'MO': '29', 'MS': '28', 'MT': '30', 'NC': '37', 'ND': '38', 'NE': '31', 'NH': '33', 'NJ': '34', 'NM': '35', 'NV': '32', 'NY': '36', 'OH': '39', 'OK': '40', 'OR': '41', 'PA': '42', 'PR': '72', 'RI': '44', 'SC': '45', 'SD': '46', 'TN': '47', 'TX': '48', 'UT': '49', 'VA': '51', 'VT': '50', 'WA': '53', 'WI': '55', 'WV': '54', 'WY': '56'}
The state FIPS code ID for each state abbreviation.
For example
IDS_FROM_ABBREVIATIONS['NJ']is34, which is the value of``NJ``.
- censusdis.states.IDS_FROM_NAMES = {'Alabama': '01', 'Alaska': '02', 'Arizona': '04', 'Arkansas': '05', 'California': '06', 'Colorado': '08', 'Connecticut': '09', 'Delaware': '10', 'District of Columbia': '11', 'Florida': '12', 'Georgia': '13', 'Hawaii': '15', 'Idaho': '16', 'Illinois': '17', 'Indiana': '18', 'Iowa': '19', 'Kansas': '20', 'Kentucky': '21', 'Louisiana': '22', 'Maine': '23', 'Maryland': '24', 'Massachusetts': '25', 'Michigan': '26', 'Minnesota': '27', 'Mississippi': '28', 'Missouri': '29', 'Montana': '30', 'Nebraska': '31', 'Nevada': '32', 'New Hampshire': '33', 'New Jersey': '34', 'New Mexico': '35', 'New York': '36', 'North Carolina': '37', 'North Dakota': '38', 'Ohio': '39', 'Oklahoma': '40', 'Oregon': '41', 'Pennsylvania': '42', 'Puerto Rico': '72', 'Rhode Island': '44', 'South Carolina': '45', 'South Dakota': '46', 'Tennessee': '47', 'Texas': '48', 'Utah': '49', 'Vermont': '50', 'Virginia': '51', 'Washington': '53', 'West Virginia': '54', 'Wisconsin': '55', 'Wyoming': '56'}
The state FIPS code ID for each state name.
For example
IDS_FROM_ABBREVIATIONS['New Jersey']is34, which is the value of``NJ``.
- censusdis.states.IL = '17'
Illinois
- censusdis.states.IN = '18'
Indiana
- censusdis.states.KS = '20'
Kansas
- censusdis.states.KY = '21'
Kentucky
- censusdis.states.LA = '22'
Louisiana
- censusdis.states.MA = '25'
Massachusetts
- censusdis.states.MD = '24'
Maryland
- censusdis.states.ME = '23'
Maine
- censusdis.states.MI = '26'
Michigan
- censusdis.states.MN = '27'
Minnesota
- censusdis.states.MO = '29'
Missouri
- censusdis.states.MS = '28'
Mississippi
- censusdis.states.MT = '30'
Montana
- censusdis.states.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,
NAMES_FROM_IDS[NJ]is"New Jersey".
- censusdis.states.NC = '37'
North Carolina
- censusdis.states.ND = '38'
North Dakota
- censusdis.states.NE = '31'
Nebraska
- censusdis.states.NH = '33'
New Hampshire
- censusdis.states.NJ = '34'
New Jersey–The Garden State
- censusdis.states.NM = '35'
New Mexico
- censusdis.states.NV = '32'
Nevada
- censusdis.states.NY = '36'
New York
- censusdis.states.OH = '39'
Ohio
- censusdis.states.OK = '40'
Oklahoma
- censusdis.states.OR = '41'
Oregon
- censusdis.states.PA = '42'
Pennsylvania
- censusdis.states.PR = '72'
Puerto Rico
- censusdis.states.RI = '44'
Rhode Island
- censusdis.states.SC = '45'
South Carolina
- censusdis.states.SD = '46'
South Dakota
- censusdis.states.TN = '47'
Tennessee
- censusdis.states.TX = '48'
Texas
- censusdis.states.UT = '49'
Utah
- censusdis.states.VA = '51'
Virginia
- censusdis.states.VT = '50'
Vermont
- censusdis.states.WA = '53'
Washington
- censusdis.states.WI = '55'
Wisconsin
- censusdis.states.WV = '54'
West Virginia
- censusdis.states.WY = '56'
Wyoming