Home » GIS Analysis » Python Minimum or Maximum Values in ArcGIS

Python Minimum or Maximum Values in ArcGIS

Python Min Max

Let’s say you have 2 separate columns in an attribute table and you want to find the minimum or maximum values between these columns. This would require a bit of Python coding.

Let’s say your fields are set up as follows:

  • The first field is Rank1
  • The second field is Rank2
  • Finally, the third is an empty field Min to store the minimum value

You can use the field calculator and minimum or maximum functions.

How to calculate minimum values using Python in ArcGIS

Right-click the empty field Min, and select “Field Calculator…”. Select the Python radio box. Use the following code:

FOR MINIMUM:

min([!Rank!, !Rank2!])

After running the field calculator with the code above, the minimum values will be calculated in the “Min” field.

Rank1Rank2Min
833
71647
7987
8178

How to calculate maximum values using Python in ArcGIS

Similarly, you can use the maximum function to attain the highest value from multiple fields.

FOR MAXIMUM:

max([!rank!, !rank2!])

After running the field calculator with the Python code above, the “Max” field will have the maximum value from the “rank1” and “rank2” fields.

Rank1Rank2Max
838
7164164
79898
81717

Maximum or minimum values from multiple fields

Python has the flexibility to evaluate the minimum and maximum values from multiple fields. After the comma, you can add additional fields to calculate minimum or maximum values.

FOR MINIMUM:

min([!Rank!, !Rank2!, !Rank3!])


FOR MAXIMUM:

max([!Rank!, !Rank2!, !Rank3!])

After running the Python code above, the minimum and maximum values will be evaluated for multiple fields.

More built-in functions

Python is a diverse programming language that can suit the needs of GIS users.

It has hundreds of functions readily available. This includes a lot of the “helpers” you can find in ArcGIS Pro.

Built-in functions can be found in the Python documentation found on the Python Docs page.

We also have a thorough list of GIS programming tutorials to help guide you. Finally, check out our guide on how to capitalize the first letters with Python.

Subscribe to our newsletter:

One Comment

  1. Thank you for this!

    Two quick questions: How can I get the name of the column from which the max (or min) value was obtained?

    Second, I analyze a row and find the max value but then I want to find the min value to the right (later in time) of the max value, how can I limit my search to min values to the right of the max value?

Leave a Reply

Your email address will not be published. Required fields are marked *