How do I add in multiple fields in the attribute table? In the attribute table I have crop types such as corn, cotton, sorghum....etc (as shown image below), in square meters. I want to generate new fields so I can calculate into acres. I am using python that would have add fields, but I would still have to provide field names, one by one (and there are a lot of field names to enter). Can I just have GIS to generate fields that are based on the existing fields without me listing them?

Image of table is attached.

enter image description here


You'll have to loop through your current fields with ListFields. Then in your AddField_management() call just add '_acres' or something that identifies it as different from your current field name.

Something along these lines:

for field in arcpy.ListFields(featureClass):
    arcpy.AddField_management(featureClass, field.name + '_acres', 'FLOAT')

If you don't want to add a new field for every field in your feature class, you'll have to add some simple conditional statements:

for field in arcpy.ListFields(featureClass):
    if field.name == 'badField': # Name of field you don't want to add acreage for
        print "Not going to add this field"
        arcpy.AddField_management(featureClass, field.name + '_acres', 'FLOAT')
  • 2
    Create a list of fields to be skipped skiplist=["skip1","skip2"] then use if field in skiplist: for the if statement – mhoran_psprep Jul 12 '12 at 17:20
  • field + '_acres' does not work.... is there other ways I can rename the existing field name? – asianpenguin Jul 12 '12 at 17:34
  • Sorry -- listing the fields only gives you the location in memory. If you print field in the loop you'll get something crazy. Try field.name (I changed the code in my answer). – Roy Jul 12 '12 at 17:39
  • You might also consider adding multiple fields with one arcpy statement by unpacking tuples: gis.stackexchange.com/questions/57380/… – Alex Tereshenkov Oct 30 '13 at 12:40

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.