<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Output Count of NULL values for Each Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1188992#M64894</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;For every field within every feature class in my dataset, I would like to produce a list with the following data:&lt;/P&gt;&lt;P&gt;1. Field Name&lt;/P&gt;&lt;P&gt;2. Field Data Type&lt;/P&gt;&lt;P&gt;3. Field Length&lt;/P&gt;&lt;P&gt;4. Field Domain&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. Count of NULL values in field&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have a script that produces 1-4 but can't seem to figure out how to produce number 5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current script:&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r"C:\gdblocation"&lt;/P&gt;&lt;P&gt;fcList = arcpy.ListFeatureClasses("*")&lt;/P&gt;&lt;P&gt;for fc in fcList:&lt;BR /&gt;print(fc)&lt;BR /&gt;fields = arcpy.ListFields(fc)&lt;/P&gt;&lt;P&gt;for field in fields:&lt;BR /&gt;print("{0},{1},{2}"&lt;BR /&gt;.format(field.name, field.type, field.length, field.domain))&lt;/P&gt;&lt;P&gt;Example of current output for each field in each feature class:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NAME, DATA TYPE, LENGTH, DOMAIN&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;What I'm trying to produce:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NAME, DATA TYPE, LENGTH, DOMAIN, &lt;STRONG&gt;# of NULL VALUES&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Sat, 02 Jul 2022 17:55:57 GMT</pubDate>
    <dc:creator>HaydenHarrison1</dc:creator>
    <dc:date>2022-07-02T17:55:57Z</dc:date>
    <item>
      <title>Output Count of NULL values for Each Field</title>
      <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1188992#M64894</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;For every field within every feature class in my dataset, I would like to produce a list with the following data:&lt;/P&gt;&lt;P&gt;1. Field Name&lt;/P&gt;&lt;P&gt;2. Field Data Type&lt;/P&gt;&lt;P&gt;3. Field Length&lt;/P&gt;&lt;P&gt;4. Field Domain&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. Count of NULL values in field&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have a script that produces 1-4 but can't seem to figure out how to produce number 5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current script:&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r"C:\gdblocation"&lt;/P&gt;&lt;P&gt;fcList = arcpy.ListFeatureClasses("*")&lt;/P&gt;&lt;P&gt;for fc in fcList:&lt;BR /&gt;print(fc)&lt;BR /&gt;fields = arcpy.ListFields(fc)&lt;/P&gt;&lt;P&gt;for field in fields:&lt;BR /&gt;print("{0},{1},{2}"&lt;BR /&gt;.format(field.name, field.type, field.length, field.domain))&lt;/P&gt;&lt;P&gt;Example of current output for each field in each feature class:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NAME, DATA TYPE, LENGTH, DOMAIN&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;What I'm trying to produce:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;NAME, DATA TYPE, LENGTH, DOMAIN, &lt;STRONG&gt;# of NULL VALUES&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any advice?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jul 2022 17:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1188992#M64894</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2022-07-02T17:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Output Count of NULL values for Each Field</title>
      <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189004#M64895</link>
      <description>&lt;P&gt;Your current code produces the record values for each row.&amp;nbsp; If a null value is encountered, None is returned so you can simply print it, using python.&lt;/P&gt;&lt;P&gt;str(!FieldName!)&amp;nbsp; # returns a string representation of None&lt;/P&gt;&lt;P&gt;When you get around to it you can query !FieldName! using count, to return the count of "None"&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jul 2022 00:17:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189004#M64895</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-03T00:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Output Count of NULL values for Each Field</title>
      <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189104#M64899</link>
      <description>&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = r"C:\gdblocation"

fcList = arcpy.ListFeatureClasses("*")

for fc in fcList:
    print(fc)
    fields = arcpy.ListFields(fc)

    field_names = [f.name for f in fields]
    null_counts = {fn: 0 for fn in field_names}
    with arcpy.da.SearchCursor(fc, field_names) as cursor:
        for row in cursor:
            for i, v in enumerate(row):
                if v is None:
                    null_counts[field_names[i]] += 1

    for field in fields:
        print("{0},{1},{2},{3}".format(field.name, field.type, field.length, field.domain, null_counts[field.name]))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Jul 2022 06:16:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189104#M64899</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-04T06:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Output Count of NULL values for Each Field</title>
      <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189226#M64902</link>
      <description>&lt;P&gt;I like using the Python API. Mostly because I learned pandas long before I ever touched arcpy, but I find it to be simple and effective. Using a geodatabase, you'll need to be using the Python API in an environment where arcpy is available to you.&lt;/P&gt;&lt;P&gt;Granted, this snipped is pretty much&amp;nbsp;&lt;EM&gt;only&amp;nbsp;&lt;/EM&gt;for the null counts. The Python API can pull out the other details of published services, but for file-based geodatabases, arcpy's the way to get the rest of the details. But I figured I'd throw another idea out there, in case it's helpful.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import GeoAccessor
import pandas as pd

df = GeoAccessor.from_featureclass('path/to/database.gdb/layername')

pd.DataFrame(df.isna().sum())&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1656985745996.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45151iFA3784A18C70E47D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1656985745996.png" alt="jcarlson_0-1656985745996.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 01:53:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189226#M64902</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-07-05T01:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Output Count of NULL values for Each Field</title>
      <link>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189793#M64935</link>
      <description>&lt;P&gt;Thank you Johannes! The only thing I had to add was an additional {4} under the print statement to include the null count.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Hayden&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 12:42:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-count-of-null-values-for-each-field/m-p/1189793#M64935</guid>
      <dc:creator>HaydenHarrison1</dc:creator>
      <dc:date>2022-07-06T12:42:19Z</dc:date>
    </item>
  </channel>
</rss>

