0

I am looking to automate the filling of a new column in an attribute field depending on the data that already exists within a column. The issue is that we obtain the data from the local council and the information prescribed in the column (in this instance, "period" i.e. 'Bronze Age, medieval etc.) varies. From my initial look, I have found over 40 different variations of how councils classify periods.

At the moment, I just highlight the entries I need to change and use the field calculator to fill in the new column.

I would imagine this would need to be a large if script but is there any easier option?

1
  • Use frequency tool on old field, bring to Excel and fill second column by your standard values. Join back to original. In excel use values list perhaps to avoid typo.
    – FelixIP
    Commented Oct 15, 2021 at 18:24

2 Answers 2

1

You can use a dictionary with a Field Calculator function or da.UpdateCursor (which i like better):

import arcpy

#Adjust these two lines:
fc = r'C:\folder\database.gdb\table'
fields = ['period', 'newfieldname']

#Dictionary of old and new value. Add all your values here, instead of many if/elifs
remap = {'bronze age':'newval1',
         'medieval':'otherval'}

with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        if row[0] in remap: #row[0] is the value of period field. This if, is checking whether the value exist in the remap dictionary
            row[1] = remap[row[0]]
            cursor.updateRow()
        #You can add an else here you want to set the new field to some value, for example 'MISSING PERIOD'
2
0

I got it working as a script just need to turn it into a tool. Thanks for your help @BERA

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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