Using ArcGIS Desktop 10.4, how can I pass Where clause and calculate Field L_STATE based on Values on another field called L_ST_CODE.

What I have in 4 Unique values of 135, 138 , 148, 136

if (L_ST_CODE == 135){
   L_STATE = "Item_1"
if (L_ST_CODE == 136){
   L_STATE = "Item_2"
if (L_ST_CODE == 138){
   L_STATE = "Item_3"
if (L_ST_CODE == 148){
   L_STATE = "Item_4"

enter image description here

  • Are you trying to use the Python Parser of the ArcGIS Field Calculator to do this?
    – PolyGeo
    Dec 15, 2017 at 23:14

4 Answers 4


You can use the Field Calculator's python parser, and use a python dictionary.

In the Pre-logic script code:

def l_state(stcode):
    stcodedict = {135: "Item_1", 136: "Item_2", 138: "Item_3", 148: "Item_4"}

    if stcode in stcodedict:
        x = stcodedict[stcode]
        return x



This checks if the value in L_ST_CODE is a key in the dictionary, and if it does then it sets the value in the field you are calculating to the value of the corresponding key.


You can do the multiple conditions in steps, and use the field calculator 4 times, one for each unique value.

For each L_ST_CODE value select and then calculate L_STATE for the selected records.


If you do not have to use the field calculator for this task, I would suggest you simply perform a "select by attribute" statement, 1 for each L_ST_Code you show above.

Then after you select the first one (i.e. "L_ST_CODE" = 135), calculate the field and enter "item1".

This could of course be done using an update cursor with arcpy if you have a lot more values to do.


Set up a look up table (nonspatial) that has the L_ST_CODE and the answer you want. You can do this by summarizing or copying existing L_ST_CODE data, adding a field, and populating it with the L_STATE value.

Then join your original table using L_ST_CODE, then do your field calculation to copy your looked up value into L_STATE. This is what the first Python answer is doing. I just like using databases. If you will be doing this change again, a database table will document what changes are to be made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.