Check if a field in a feature class is totally empty to delete it?

781
4
Jump to solution
02-02-2023 09:37 PM
JohannesBierer
Occasional Contributor III

Hello,

I want to delete all empty fields in a feature class (arcgis pro 3.0 - notebooks) - with no sucess. The following script doesn't work, it prints fields as count = 0 which have valid attributes.

Any better ideas?

 

fc = "Merge_1"

fields = [f.name for f in arcpy.ListFields(fc) if not f.required]

for field in fields:
    count = 0
    with arcpy.da.SearchCursor(fc, field) as cursor:
        for row in cursor:
            
            if row[0] is None or row[0] in ["", " ", "0"]:
                count += 0
            else:
                count += 1
                break
                
    print(field, count)

 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

That is a problem.  People should really set up Excel's "Data Validation" for their spreadsheet columns if they are using Excel for data entry or acquisition.


... sort of retired...

View solution in original post

4 Replies
JohannesBierer
Occasional Contributor III

Sorry it works sucessfully ...

0 Kudos
DanPatterson
MVP Esteemed Contributor

since you have run it against something to compare to, what does this return

Field Statistics To Table (Data Management)—ArcGIS Pro | Documentation

wondering what is returned if All types and the options for  nulls, count and unique

 


... sort of retired...
JohannesBierer
Occasional Contributor III

Didn't knowed this tool, if I run it with one empty field I want to delete I get something like this:

Sorry it's in german ...

JohannesBierer_0-1675417150681.png

I think the problem with this tool will be that it's some kind of chaotic data merge out of excel files in the fc. The fields to delete could contain  Null values, "", "0", " " ... .

 

DanPatterson
MVP Esteemed Contributor

That is a problem.  People should really set up Excel's "Data Validation" for their spreadsheet columns if they are using Excel for data entry or acquisition.


... sort of retired...