HOW TO

Count the number of null values in an attribute table using ArcGIS API for Python

Last Published: October 27, 2022

Summary

Null values denote when a field has no value. Analyzing numeric data containing null values does not accurately represent the data. In cases where multiple fields contain null values in an attribute table, it is sometimes necessary to count the number of null values that exist in the fields. Counting the null values manually is impractical and tedious when working with a large dataset.

This article describes the workflow to count the number of null values in every field of an attribute table using ArcGIS API for Python.

Procedure

  1. Import the necessary modules:
import arcgis
import pandas
  1. Specify the feature to be used as the dataframe.
in_fc = r"<Feature_Class_Folder_Path>"
df = pandas.DataFrame.spatial.from_featureclass(in_fc)
  1. Identify and count the number of null values and print the result.
idx = df.isnull()
print(idx.sum())

The following shows the sample of a full script:

import arcgis
import pandas

infc = r"C:\Users\User\Desktop\Test_Folder\TestProject\Test.gdb\testing"
sedf = pandas.DataFrame.spatial.from_featureclass(infc)

idx = sedf.isnull() 
print(idx.sum())

The number of null values for each field in the attribute table is displayed in the Python window.

The number of null values of each field displayed in the Python window.

Article ID: 000028560

Software:
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options
Esri Support AI Chatbot