1

I'm attempting to populate a newly created field with values dependent on an existing field.

The new field has text data type. The existing field is double data type. This is the python code I've been trying. It runs, but the values remain

def Reclass(Crime):
 if (Hierarchy == 1):
 return "Murder-Manslaughter"
 elif (Hierarchy == 2):
 return "Forcible Rape"
 elif (Hierarchy == 3):
 return "Robbery"
 elif (Hierarchy == 4):
 return "Aggravated Assault"

enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 4, 2019 at 0:35
0

1 Answer 1

4

You need to pass the Hierarchy field to the function, not the Crime field.

crime = 
Reclass(!Hierarchy!)
def Reclass(Hierarchy):
 if (Hierarchy == 1):
 return "Murder-Manslaughter"
 elif (Hierarchy == 2):
 return "Forcible Rape"
 elif (Hierarchy == 3):
 return "Robbery"
 elif (Hierarchy == 4):
 return "Aggravated Assault"

Or even neater, use a dict lookup:

def Reclass(Hierarchy):
 reclass = {
 1: "Murder-Manslaughter",
 2: "Forcible Rape",
 3: "Robbery",
 4: "Aggravated Assault",
 }
 return reclass.get(Hierarchy)
answered Oct 4, 2019 at 1:51
3
  • Thanks! Do you know of any good resources for learning python with GIS? Commented Oct 4, 2019 at 2:53
  • No, I picked it up as I went along. Try gis.stackexchange.com/search?q=learning+python Commented Oct 4, 2019 at 3:43
  • @BenD On Udemy there is ArcPy for Python Developers using ArcGIS Pro which is an eLearning course I wrote and recorded. Commented Oct 4, 2019 at 11:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.