6

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

1 Answer 1

14

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.

2
  • @Noel Peterson, ah right! Forgot about dictionaries. Thanks for your help! It worked.
    – kaoscify
    Nov 1, 2011 at 21:22
  • 2
    Nice concise answer, thanks for contributing. I suggest editing the answer and inserting the comment re: using a new field for reversibility. Doing so gives more visibility and builds an integrated, more complete, answer. Nov 2, 2011 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.