[GIS] Converting state name abbreviations to full names using ArcGIS Field Calculator

arcgis-desktopfield-calculatorpython-parser

I have a data table with columns that includes city names (ex: San Jose) and state name abbreviations (ex: CA). Is there a way to define the state names as their full names (i.e., CA = California) and then combine city name and state name (ex: San Jose, California)?

I have approximately 120 records. So what I think I have to do is define each state as their full names (ex: NY = New York, FL = Florida, and so on) first. I guess I could create a new field and add these to it, and then combine this new field with full state names with city names? Does that make sense or is there another way to do it? Need to achieve this using Python.

Something like the following, but it doesn't seem right:

def stateNames(): # Add this pre-logic script in the code block
  CA = 'California'
  FL = 'Florida'
  GA = 'Georgia'
  HI = 'Hawaii'
  MN = 'Minnesota'
  NY = 'New York'
  # and so on...
return stateNames()

stateNames + !City_Name! # Add this in the box below pre-logic script

Best Answer

You could include the Python dictionary of state abbreviation:full-name pairs here

states = {
    'AK': 'Alaska',
    'AL': 'Alabama',
    'AR': 'Arkansas',
    # etc...
    }

as the Codeblock in Field Calculator, and then use something like the following as the actual calculation:

!City! + ", " + states[!State!]

I should add that you could perform this calculation on either a new (text) field, or on the existing City field (or any other already-existing text field). I would recommend creating a new one, as you will otherwise not be able to easily revert to a field of only city names if you ever need them.