[GIS] Doing If/Then over multiple data columns in Python Parser of ArcGIS Field Calculator

arcgis-desktopfield-calculatorpython-parser

I have some VB code saved that looks at two columns of data, and populates a third with the low value.

Pre-logic Script Code:

Dim output as double
if [MIN_LEFT] < [MIN_RIGHT] Then
  output = [MIN_LEFT]
else
  output = [MIN_RIGHT]
end if

low = output

I've never used Python before, but I see that I'm going to have to if I want to do this calculation! But I'm stumped by the comparison of the two columns, and how to define that. Can anyone help me? (And I apologize if this is overly basic!)

Best Answer

What you want to do in the codeblock for Python is define a function, and then call the function using your attributes as parameters as follows:

def comparison(left,right):
    if left < right:
        return left
    else:
        return right

output = comparison(!MIN_LEFT!,!MIN_RIGHT!)

Then, all you need in the calculation is output, as you already had for VBScript.