-2

This question already has an answer here:

In ArcGIS 10.5, I am building a model that should convert a field of coded values to another code. This seems like it should be a simple if/then statement but I am not getting it. To simplify the process, I populated the target field with the source field's values and then intend on using python to transpose the values. It should be considered a string, but the values are numerical.

In the "Calculate Field" code block:

def reclass:
if TP_Condi = 3:
return 1
elif TP_Condi = 2:
return 8
elif TP_Condi = 1:
return 3
else:
return "error"

marked as duplicate by BERA, Dan C, tinlyx, whyzar, xunilk Feb 23 '18 at 19:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Normally, equality in Python is tested with "==" rather than "=" as it is in SQL. Furthermore, you are mixing Integers and Strings as your return value. From your question I understand you want to have Strings in your new field, so either use return str(1) or just return '1' – s6hebern Feb 23 '18 at 16:55
  • 2
    Instead of posting the same question again, edit your question from yesterday and clarify the questions in the comments and you will get a correct answer. – BERA Feb 23 '18 at 16:57
0

I assume you are not getting a syntax error, so your indents are OK. I do notice you don't pass the field name in the function call (first Line). So it would not have any value.

def reclass([TP_Condi]):

I would use a join, not Python, to solve this problem, but to each his own..

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