I am brand new to coding, have no background at all. Basically I have about 200 tables with the same info listed under slightly different attribute table headings and I am trying to rename them to match so I can merge them all and move to ArcSDE eventually. I had issues trying it with a few tables(8 total) as a shorter trial run in model builder because the names "REC", "REC_SS" and REC_" did not all exist in just those few files but do in the larger schema of 200. Now I am getting a general error in GIS of 999999 and an error invalid syntax error 000539 but my code is reading fine in a trial python site.

Here is my code and I attached a screen shot too. enter image description here

This is my code block:

def customReplace(fieldValue):
    repList = ("REC")
    repValue = "REC_CODE"
    for item in repList:      
       if item in fieldValue:
         fieldValue = fieldValue.replace(item, repValue)
    return fieldValue

My field expression is:

customReplace ("REC_CODE")
  • Could you explaing what the code is supposed to do?
    – BERA
    Mar 9, 2018 at 19:28
  • delete the columns with the same info that are named slightly differently. I want to keep the column "REC_CODE" and rename/merge the other columns to it. Mar 9, 2018 at 19:32
  • You cant do that with Field Calculator. You mean that is what the Model is supposed to do?
    – BERA
    Mar 9, 2018 at 19:34
  • yes the model. im using the calculate field function from arc toolbox to replace the wrong named fields. Mar 9, 2018 at 19:35
  • You cant rename fields with Field Calcultor. You need Alter Field desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/…
    – BERA
    Mar 9, 2018 at 19:38

1 Answer 1


If all the headers are in the same order in all tables, you can use the header index to rename the headers to your pattern. But you won't be able to do this using the Field Calculator. This tool was meant to be used to calculate the value of a field, not to change the structure of a table, hence the reason why you cannot use AlterField_management on your code block.

You will need to write a python script to do this, it can be a little tough as you do not have any experience in programming. But, if you insist, I suggest making through the basics of python and programming logic first, then looking at arcpy.

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.