How To: Select ArcGIS records containing odd or even
values in a numeric field using Python in ArcGIS Pro
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.
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')
[SAMPLE: I select even values in an ODD_No field, to make them even later --
arcpy.management.SelectLayerByAttribute('House_Number', 'SUBSET_SELECTION', 'MOD ("ODD_HN",
2) = 0')]
3. Press Enter.
4. In the attribute field, click the Switch 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')
[SAMPLE: I select odd values in an EVEN_No field, to make them odd later --
arcpy.management.SelectLayerByAttribute('House_Number', 'SUBSET_SELECTION', 'MOD ("EVEN_HNo",
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 option in the Selection
group:
arcpy.management.SelectLayerByAttribute('<Feature layer>', 'CLEAR_SELECTION')
Last Published: 9/16/2021
Additions: to change odd/even field values to even/odd, use field calc on the right field and enter <field
Name> + 1. This applies to both sides following the selection using the above python script!