ghoshsn

Python code to create a field based on another field. why is this not working?

Discussion created by ghoshsn on Apr 26, 2012
Latest reply on Mar 18, 2014 by curtvprice
I have one field in the attribute table called CO . This field has codes of counties like 017, 049, so on. Now I want to create a field called CO_NAME which will have names of counties based on county codes like "Bourbon" for 017, "Clark" for 049 and so on.


I go to field calculator, select python and check show codeblock

This is what I enter

def coname(CO):
  if CO==067:
   return "Fayette"
elif CO==209:
  return "Scott"
elif CO==239:
  return "Woodford"
elif CO==017:
  return "Bourbon"
elif CO==049:
  return "Clark"
elif CO==073:
  return "Franklin"
elif CO==081:
  return "Grant"
elif CO==097:
  return "Harrison"
elif CO==187:
  return "Owen"


CO_NAME =
coname(!CO!)

What is my mistake here? Thanks.
Sudeshna

Outcomes