Reclassify a field in model builder

270
6
Jump to solution
11-25-2013 09:21 AM
MeredithGreen
New Contributor III
I have a fairly large model with a field in the table labeled RETURN_PER for types of flooding (2yr, 5yr, 10yr, 25yr, 50yr, 100yr, 200yr, 500yr etc.)  However the field needs to show these values as percents (50pct, 20pct, 10pct, 04pct etc.)  I need to make the change at the end of the model but am having a hard time getting the field to change values.  So far my thought process has gone Add Field -> Calculate Field (New field equals original field) -> Calculate Field (Recalculate Original field adding Reclassify script [see below] to show percentages)  -> Delete New Field.

def Reclass(variable1):
  if variable1 == "2":
    return "50pct"
  if variable1 == "5":
    return "20pct"
  if variable1 == "10":
    return "10pct"
  if variable1 == "25":
    return "04pct"
  if variable1 == "50":
    return "02pct"
  if variable1 == "100":
    return "01pct"
  if variable1 == "200":
    return "0_5pct"
  if variable1 == "500":
    return "0_2pct"

Any other suggestions would be greatly appreciated.

Thanks
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Okay so I got it working once I added def Reclass but now the table is automatically filling in the field with the domain code description that corresponds with the percentages.  Is there a way to correct this so it puts in the percentages instead?


Give an example of what would you want it to appear like.  Are you saying you want it to appear as 50pct, but it appears as something else?  Removing the domain from the field is the easiest way to get it to show the native value you calculated.  Otherwise you would have to alter the domain descriptions to appear the way you want (even if the value and the description are identical to each other).

View solution in original post

0 Kudos
6 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Meredith,

Are you receiving any errors?

When you create the new field, are you creating it as a "TEXT" field?  If it is a Long Integer, Short Integer, or Double try the following w/o the quotes around the value:

def Reclass(variable1):
     if variable1 == 2:
         return "50pct"
  ....
0 Kudos
MeredithGreen
New Contributor III
Hi Meredith,

Are you receiving any errors?

When you create the new field, are you creating it as a "TEXT" field?  If it is a Long Integer, Short Integer, or Double try the following w/o the quotes around the value:

def Reclass(variable1):
     if variable1 == 2:
         return "50pct"
  ....


The new field is a text field with a length of 6.  The final field that I'm trying to reclassify has to be a text field with a length of six.  When I process I don't see any error messages but I also don't see any change in the table.
0 Kudos
RichardFairhurst
MVP Honored Contributor
The new field is a text field with a length of 6.  The final field that I'm trying to reclassify has to be a text field with a length of six.  When I process I don't see any error messages but I also don't see any change in the table.


You did not provide your expression.  It needs to contain the field name of the field with the original values you are evaluating and the calculation needs to be done on the field that will have the reclassified values.  Something like:

def Reclass(!RETURN_PER!)
0 Kudos
MeredithGreen
New Contributor III
You did not provide your expression.  It needs to contain the field name of the field with the original values you are evaluating and the calculation needs to be done on the field that will have the reclassified values.  Something like:

def Reclass(!RETURN_PER!)


Okay so I got it working once I added def Reclass but now the table is automatically filling in the field with the domain code description that corresponds with the percentages.  Is there a way to correct this so it puts in the percentages instead?
0 Kudos
RichardFairhurst
MVP Honored Contributor
Okay so I got it working once I added def Reclass but now the table is automatically filling in the field with the domain code description that corresponds with the percentages.  Is there a way to correct this so it puts in the percentages instead?


Give an example of what would you want it to appear like.  Are you saying you want it to appear as 50pct, but it appears as something else?  Removing the domain from the field is the easiest way to get it to show the native value you calculated.  Otherwise you would have to alter the domain descriptions to appear the way you want (even if the value and the description are identical to each other).
0 Kudos
MeredithGreen
New Contributor III
Give an example of what would you want it to appear like.  Are you saying you want it to appear as 50pct, but it appears as something else?  Removing the domain from the field is the easiest way to get it to show the native value you calculated.  Otherwise you would have to alter the domain descriptions to appear the way you want (even if the value and the description are identical to each other).


Removing the domain from the field solved it.  Thanks for the input!
0 Kudos