How to calculate minimum values using Python in ArcGIS
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:
- First field as “rank1”
- Second field as “rank2”
- Third is an empty field “Min” to store the minimum value
Use Field Calculator
Right-click the empty field “Min”, and select “Field Calculator…”. Select the Python radio box. Use the following code:
After running the field calculator with the code above, the minimum values will be calculated in the “Min” field.
How to calculate maximum values using Python in ArcGIS
Similarly, you can use the maximum function to attain the highest value from multiple fields.
After running the field calculator with the Python code above, the “Max” field will have the maximum value from the “rank1” and “rank2” fields.
How to get maximum or minimum values using Python for 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.
min([!rank!, !rank2!, !rank3!])
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.
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.