1

I have an attribute table with 100 columns (values are float and not NULL; more than 3000 rows). Using ArcGIS 10.6

  • I want to calculate the mean value of every field in a shapefile separately (like summary statistic works);
  • and use the resulting value for deleting the field: if the Mean value of the field lower than 0.6- delete the field from the table.

How can I use the Mean values of the fields in a for loop in order to delete the unnecessary fields from a table with python?

Yogesh Chavan
2,8672 gold badges11 silver badges26 bronze badges
asked Jan 23, 2021 at 16:22
2
  • 2
    What have you tried? What are your python skills like? This would be s relatively simple coding exercise. Commented Jan 23, 2021 at 16:41
  • Basic python skill. I work with model builder mainly, but for this I can not find any solution. Commented Jan 23, 2021 at 17:24

1 Answer 1

4

This would be difficult and I suspect overtly complex if implemented in modelbuilder, a python solution would be much easier to run.

Here is the code that will achieve what you need:

import arcpy
 
table = r"C:\Scratch\fGDB_Scratch.gdb\test"
# Creates an array using all fields in table
array = arcpy.da.TableToNumPyArray(table,"*")
# Create a list of field names
lstFields = list(array.dtype.names)
# Remove OBJECTID from list
# You add other fields to remove here, eg. text fields
lstFields.remove("OBJECTID")
# Compute mean and if it falls below limit add to delete list
print("identifying fields to delete...")
toDelete = list()
for fn in lstFields:
 if array[fn].mean() < 3.6:
 toDelete.append(fn)
# Drop fields
print("Deleting fields...")
arcpy.DeleteField_management(table,toDelete)
print("Done!")

Once you have modified this code to your case drop this code into the Python console window in ArcMap or run it from an IDE.

In my test scenario I have a table and I'm checking the mean of the fields to see if they are below the value of 3.6, obviously adapt it to your scenario. I would recommend you do this from a backed up version in case your logic was wrong. My test table was this:

Test table

answered Jan 23, 2021 at 18:51
1
  • 1
    Thank you!!! It works fine! Commented Jan 23, 2021 at 21:26

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.