# calculate feild using phyton if function

405
5
06-28-2021 09:00 AM
Labels (1)
by
New Contributor II

hello, i want to calculate feild using phyton if function to do the following :

if Height_Delta is greater than 0 write in the status cell " Uprise"

if Height_Delta is less than 0 write in the status cell "Downrise"

image is attached

can anyone can help with the code ?

thanks.

1 Solution

Accepted Solutions
MVP Esteemed Contributor
``["Down_rise", "Up_rise"][!Height_Delta! > 0]``

goes under Status =  line

not in the code block

some background

Fundamentals of field calculations—ArcGIS Pro | Documentation

... sort of retired...
5 Replies
MVP Esteemed Contributor
``````Height_Delta = 5  # ---- example value

["Down_rise", "Up_rise"][Height_Delta > 0]
'Up_rise'``````

Remember to put ! marks around Height_Delta ( !Height_Delta! ) since it is a python field calculator expression

... sort of retired...
by
New Contributor II

can u tell where to write each line of the code in the feild calculator window ?

image is attached here :

thank u

MVP Esteemed Contributor
``["Down_rise", "Up_rise"][!Height_Delta! > 0]``

goes under Status =  line

not in the code block

some background

Fundamentals of field calculations—ArcGIS Pro | Documentation

... sort of retired...
MVP Esteemed Contributor

Another alternative.

Expression:

``Slope(!Height_Delta!)``

Code Block:

``````def Slope(HT):
if HT< 0:
return 'Downrise'
else:
return 'Uprise'``````

Think Location
MVP Esteemed Contributor

expression

``code_block(!Height_Delta!)``

code block

``````def code_block(fld)
"""code block isn't really needed"""
return ["Down_rise", "Up_rise"][fld > 0]``````

but as you can see it really isn't needed

... sort of retired...