2

I would like to populate the alias names for the fields in the ACS 2014 5 year estimates file geodatabase (all 11439 of them). The ACS fgdb comes with the short_name and long_name in the metadata table. I have exported this into an excel spreadsheet, and think this would be best done using arcpy.AlterField_management() with openpyxl.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 26, 2015 at 23:26

1 Answer 1

3

To simplify matters, I'll assume your excel spreadsheet is really a csv file with no headers and is formed like: field_name,alias:

import arcpy, csv
csvfile = "<path to file>"
FC = "<path to feature class>" 
#List of tuples
name_alias = [rows for rows in csv.reader(open(csvfile))]
errors = []
for name,alias in name_alias:
 try:
 print("Altering.....{}".format(name))
 arcpy.AlterField_management(FC, name, new_field_alias=alias)
 except Exception as e:
 errors.append(name) #Keep running list of field names that failed.
 print(e)
 pass
if errors: print errors

Improving this to support Excel files should be straightforward enough.

If for whatever reason failure occurs (missing field, schema lock, improper name, etc.), the error will be printed and processing continued.

answered Aug 27, 2015 at 1:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.