Skip to main content
added 6 characters in body
Source Link
user2856
  • 74.3k
  • 7
  • 123
  • 208

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)

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)

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)
Source Link
user2856
  • 74.3k
  • 7
  • 123
  • 208

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)