I am running a field calculation which is [field A]/[field B]. Some of the values in field B are zero. Is there a script I could use to turn results in the calculation where the denominator is zero into -99 instead of creating an error message?
Put this in the code block:
def my_function(numerator, denominator): if denominator == 0: return -99 else: return numerator/denominator
...and this in the expression below the code block:
my_function(!CHSCH04!,!TOSCH04!)
Make sure you've changed to the Python parser.
Maybe I am messing up the syntax. Here is what I have:
Codeblock:
def my_function(numerator, denominator):
if denominator == 0:
return -99
else:
return numerator/denominator
PRCHSCH =
my_function( [CHSCH04] , [TOSCH04] )
Still returning an error. Thanks for the help.
Oh, sure, yes I missed that part:
Maybe the result can return just the value of -99 instead of numerator/-99 if the denominator is 0. Rest seems perfect.
Something like:
def my_function(numerator, denominator): if denominator == 0: denominator = -99 return numerator/denominator
Expression:
my_function( !YOUR_NUMERATOR_FIELD!, !YOUR_DENOMINATOR_FIELD! )
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.