AnsweredAssumed Answered

Get a count of field values

Question asked by jborgion Champion on Jan 8, 2020
Latest reply on Jan 13, 2020 by william.kalande@gmail.com

I'm working with some data that is a ridiculously large table (184 fields) and I would like to ***** how many instances of of each field are non-null.  In other words if the values are more more often null, I'll drop the field(s).  For now I've written a script that performs an iterative selection for each field, and as you can imagine with 184 fields and a few thousand records it's pretty slow.  I tried a couple other approaches that failed, but I have to think there is a better way to get a count of records for which a given field is populated.  Here is what I've done to date:  

 

import arcpy

table = r'J:\some\path\to\file.gdb\tableName'
fields = []

for f in arcpy.ListFields(table):
    fields.append(f.name)

arcpy.MakeTableView_management(table,'tv')

for f in fields:
    select = f'{f} is not null'
    arcpy.SelectLayerByAttribute_management('tv','NEW_SELECTION',select)
    c = arcpy.GetCount_management('tv')
   
    print('Field {} has {} non-null records'.format(f,c[0]))

Outcomes