HOW TO

Select ArcGIS records containing odd or even values in a numeric field using Python in ArcGIS Pro

Last Published: September 13, 2023

Summary

In ArcGIS Pro, it is possible to select specific records containing odd or even numbers from a numeric field in the attribute table using Python.

The following image shows the example of records for selected odd numbers from a numeric field.

The example of records for selected odd numbers from a numeric field.

Procedure

  1. In ArcGIS Pro, click the Analysis tab on the top ribbon. Click the drop-down menu next to Python, and click Python Window.
  2. In the Python window, insert the following command to select records with even values in a numeric field:
arcpy.management.SelectLayerByAttribute('<Feature layer>', 'SUBSET_SELECTION', 'MOD ("<Field name>",  2)  = 0')
  1. Press Enter.
  2. In the attribute field, click the Switch The Switch Selection icon to select the opposite results of the previous selection. option to select records with odd values in the numeric field.

Alternatively, in the Python window, insert the following command to select records with odd values in the numeric field:

arcpy.management.SelectLayerByAttribute('<Feature layer>', 'SUBSET_SELECTION', 'MOD ("<Field name>",  2)  = 1')

To use both Python commands consecutively, insert the following command to remove the previous selection before selecting new records or click the Clear The Clear icon to clear the previous selection. option in the Selection group:

arcpy.management.SelectLayerByAttribute('<Feature layer>', 'CLEAR_SELECTION')

Article ID:000026383

Software:
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options