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"
1 Answer 1
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
-
Thanks! Do you know of any good resources for learning python with GIS?Ben D.– Ben D.2019年10月04日 02:53:13 +00:00Commented Oct 4, 2019 at 2:53
-
No, I picked it up as I went along. Try gis.stackexchange.com/search?q=learning+pythonuser2856– user28562019年10月04日 03:43:32 +00:00Commented 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.2019年10月04日 11:40:38 +00:00Commented Oct 4, 2019 at 11:40
Explore related questions
See similar questions with these tags.
lang-py