Last active
April 19, 2024 14:04
-
-
Save rogerallen/1583593 to your computer and use it in GitHub Desktop.
A Python Dictionary to translate US States to Two letter codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# United States of America Python Dictionary to translate States, | |
# Districts & Territories to Two-Letter codes and vice versa. | |
# | |
# Canonical URL: https://gist.github.com/rogerallen/1583593 | |
# | |
# Dedicated to the public domain. To the extent possible under law, | |
# Roger Allen has waived all copyright and related or neighboring | |
# rights to this code. Data originally from Wikipedia at the url: | |
# https://en.wikipedia.org/wiki/ISO_3166-2:US | |
# | |
# Automatically Generated 2021-09-11 18:04:36 via Jupyter Notebook from | |
# https://gist.github.com/rogerallen/d75440e8e5ea4762374dfd5c1ddf84e0 | |
us_state_to_abbrev = { | |
"Alabama": "AL", | |
"Alaska": "AK", | |
"Arizona": "AZ", | |
"Arkansas": "AR", | |
"California": "CA", | |
"Colorado": "CO", | |
"Connecticut": "CT", | |
"Delaware": "DE", | |
"Florida": "FL", | |
"Georgia": "GA", | |
"Hawaii": "HI", | |
"Idaho": "ID", | |
"Illinois": "IL", | |
"Indiana": "IN", | |
"Iowa": "IA", | |
"Kansas": "KS", | |
"Kentucky": "KY", | |
"Louisiana": "LA", | |
"Maine": "ME", | |
"Maryland": "MD", | |
"Massachusetts": "MA", | |
"Michigan": "MI", | |
"Minnesota": "MN", | |
"Mississippi": "MS", | |
"Missouri": "MO", | |
"Montana": "MT", | |
"Nebraska": "NE", | |
"Nevada": "NV", | |
"New Hampshire": "NH", | |
"New Jersey": "NJ", | |
"New Mexico": "NM", | |
"New York": "NY", | |
"North Carolina": "NC", | |
"North Dakota": "ND", | |
"Ohio": "OH", | |
"Oklahoma": "OK", | |
"Oregon": "OR", | |
"Pennsylvania": "PA", | |
"Rhode Island": "RI", | |
"South Carolina": "SC", | |
"South Dakota": "SD", | |
"Tennessee": "TN", | |
"Texas": "TX", | |
"Utah": "UT", | |
"Vermont": "VT", | |
"Virginia": "VA", | |
"Washington": "WA", | |
"West Virginia": "WV", | |
"Wisconsin": "WI", | |
"Wyoming": "WY", | |
"District of Columbia": "DC", | |
"American Samoa": "AS", | |
"Guam": "GU", | |
"Northern Mariana Islands": "MP", | |
"Puerto Rico": "PR", | |
"United States Minor Outlying Islands": "UM", | |
"U.S. Virgin Islands": "VI", | |
} | |
# invert the dictionary | |
abbrev_to_us_state = dict(map(reversed, us_state_to_abbrev.items())) |
@pnojai take a look at : https://pypi.org/project/us/
thanks a lot
Thank you for sharing this information
@sandlerj It's worked very well, and thank you
Thank you!
Commenting as well, so everyone gets spam on this gist! haha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
us_state_to_abbrev = {
"Alabama": "AL",
"Alaska": "AK",
"Arizona": "AZ",
"Arkansas": "AR",
"California": "CA",
"Colorado": "CO",
"Connecticut": "CT",
"Delaware": "DE",
"Florida": "FL",
"Georgia": "GA",
"Hawaii": "HI",
"Idaho": "ID",
"Illinois": "IL",
"Indiana": "IN",
"Iowa": "IA",
"Kansas": "KS",
"Kentucky": "KY",
"Louisiana": "LA",
"Maine": "ME",
"Maryland": "MD",
"Massachusetts": "MA",
"Michigan": "MI",
"Minnesota": "MN",
"Mississippi": "MS",
"Missouri": "MO",
"Montana": "MT",
"Nebraska": "NE",
"Nevada": "NV",
"New Hampshire": "NH",
"New Jersey": "NJ",
"New Mexico": "NM",
"New York": "NY",
"North Carolina": "NC",
"North Dakota": "ND",
"Ohio": "OH",
"Oklahoma": "OK",
"Oregon": "OR",
"Pennsylvania": "PA",
"Rhode Island": "RI",
"South Carolina": "SC",
"South Dakota": "SD",
"Tennessee": "TN",
"Texas": "TX",
"Utah": "UT",
"Vermont": "VT",
"Virginia": "VA",
"Washington": "WA",
"West Virginia": "WV",
"Wisconsin": "WI",
"Wyoming": "WY",
"District of Columbia": "DC",
"American Samoa": "AS",
"Guam": "GU",
"Northern Mariana Islands": "MP",
"Puerto Rico": "PR",
"United States Minor Outlying Islands": "UM",
"U.S. Virgin Islands": "VI",
"AL": "AL",
"AK": "AK",
"AZ": "AZ",
"AR": "AR",
"CA": "CA",
"CO": "CO",
"CT": "CT",
"DE": "DE",
"FL": "FL",
"GA": "GA",
"HI": "HI",
"ID": "ID",
"IL": "IL",
"IN": "IN",
"IA": "IA",
"KS": "KS",
"KY": "KY",
"LA": "LA",
"ME": "ME",
"MD": "MD",
"MA": "MA",
"MI": "MI",
"MN": "MN",
"MS": "MS",
"MO": "MO",
"MT": "MT",
"NE": "NE",
"NV": "NV",
"NH": "NH",
"NJ": "NJ",
"NM": "NM",
"NY": "NY",
"NC": "NC",
"ND": "ND",
"OH": "OH",
"OK": "OK",
"OR": "OR",
"PA": "PA",
"RI": "RI",
"SC": "SC",
"SD": "SD",
"TN": "TN",
"TX": "TX",
"UT": "UT",
"VT": "VT",
"VA": "VA",
"WA": "WA",
"WV": "WV",
"WI": "WI",
"WY": "WY",
"DC": "DC",
"AS": "AS",
"GU": "GU",
"MP": "MP",
"PR": "PR",
"UM": "UM",
"VI": "VI",
}
needed this for standardizing the column where some values were full names and some were abbreviations