<?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 Re: Search for blank/empty and NULL records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204251#M65362</link>
    <description>&lt;P&gt;I was able to get what I need with the following. My only other question is how do I get the counter to on top of the OBJECTID rows?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = ["OBJECTID", "PN1"]
where = "PN1 = ' ' OR PN1 IS  NULL"
counter = 0
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    for row in cursor:
        if row[1]in ["", " ", None]:
            counter += 1
            print ("OBJECTID {0}".format(row[0]) + "has a NULL value in field")
            
print ("{} {} records have blank/empty or NULL records".format(row[0],counter))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results;&lt;/P&gt;&lt;P&gt;OBJECTID 44has a NULL value in field&lt;BR /&gt;OBJECTID 47has a NULL value in field&lt;BR /&gt;OBJECTID 88has a NULL value in field&lt;BR /&gt;OBJECTID 106has a NULL value in field&lt;BR /&gt;OBJECTID 108has a NULL value in field&lt;BR /&gt;OBJECTID 121has a NULL value in field&lt;BR /&gt;OBJECTID 130has a NULL value in field&lt;BR /&gt;OBJECTID 182has a NULL value in field&lt;BR /&gt;OBJECTID 210has a NULL value in field&lt;BR /&gt;210 9 records have blank/empty or NULL records&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i put the "210 9 records have blank/empty or NULL records" on top like so&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;210 9 records have blank/empty or NULL records.&lt;/P&gt;&lt;P&gt;OBJECTID 44has a NULL value in field&lt;BR /&gt;OBJECTID 47has a NULL value in field&lt;BR /&gt;OBJECTID 88has a NULL value in field&lt;BR /&gt;OBJECTID 106has a NULL value in field&lt;BR /&gt;OBJECTID 108has a NULL value in field&lt;BR /&gt;OBJECTID 121has a NULL value in field&lt;BR /&gt;OBJECTID 130has a NULL value in field&lt;BR /&gt;OBJECTID 182has a NULL value in field&lt;BR /&gt;OBJECTID 210has a NULL value in field&lt;/P&gt;</description>
    <pubDate>Thu, 18 Aug 2022 17:51:53 GMT</pubDate>
    <dc:creator>2Quiker</dc:creator>
    <dc:date>2022-08-18T17:51:53Z</dc:date>
    <item>
      <title>Search for blank/empty and NULL records</title>
      <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204207#M65358</link>
      <description>&lt;P&gt;I am trying to print empty/blank or Null records with the following but when nothing is printed and there is empty/blank and Null records in the layer. I would also like to print the number of empty/blank or Null records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = "C:/Temp/Test.gdb/feature Class"

fields = ["OBJECTID", "PN1"]

for field in fields:
    where = field + " IS " " OR NULL"
    try:      
        with arcpy.da.SearchCursor(fc, fields, where) as cursor:
            for row in cursor:
                print("OBJECTID {0}").format(row[0]) +  " has a Empty/ Blank or NULL value in field " + field
    except RuntimeError:
        pass

del cursor

counter = 0
with arcpy.da.SearchCursor(fc,["OBJECTID","PN1"]) as cursor:
    for row in cursor:
        if row[1] in ["", " ", None]:
            counter += 1
            print('{}  {} is null {} times'.format(row[0],row[1],counter))
        else:
            pass&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 15:35:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204207#M65358</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-08-18T15:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search for blank/empty and NULL records</title>
      <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204215#M65359</link>
      <description>&lt;P&gt;Without testing it right this minute it looks like you have something like this&lt;/P&gt;&lt;P&gt;field IS " " OR NULL&lt;/P&gt;&lt;P&gt;and I think that might evaluate as&lt;/P&gt;&lt;P&gt;(field IS " ") OR (NULL)&lt;/P&gt;&lt;P&gt;which means nothing to me. You would need to write it as&lt;/P&gt;&lt;P&gt;field = " " OR field IS NULL&lt;/P&gt;&lt;P&gt;Then the problem becomes that the first part only matches if the string contains exactly one space. You probably want an empty string,&lt;/P&gt;&lt;P&gt;field = "" OR field IS NULL&lt;/P&gt;&lt;P&gt;I have actually had datasets that had fields with one space in them, those can drive you crazy. You could probably find a neat SQL way to strip extra spaces and then check the length of the result string but I don't know how to do that in SQL. In python for example this gives 0 as the return: len(" &amp;nbsp; &amp;nbsp;&amp;nbsp; ".strip())&lt;/P&gt;&lt;P&gt;Personally I have taken to using pandas for things like this, it does the hard parts internally where I don't see them and does them 10x as fast. It's another learning curve though. Later for that maybe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 15:42:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204215#M65359</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2022-08-18T15:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Search for blank/empty and NULL records</title>
      <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204235#M65360</link>
      <description>&lt;P&gt;I was able to get something printed with the suggestion but it repeats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = ["OBJECTID", "PN1"]

for field in fields:
    where = "PN1 = ' ' OR PlN1 IS  NULL"
    try:      
        with arcpy.da.SearchCursor(fc, fields, where) as cursor:
            for row in cursor:
                #print("Null value in row {0}".format(row[0], row[1]))
                print ("OBJECTID {0}".format(row[0]) + "has a NULL value in field")
##                result = arcpy.GetCount_management(fc).getOutput(0)
##                print ('{} has {} records'.format(fc, result[0]))
    except RuntimeError:
        pass

del cursor&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;OBJECTID 44has a NULL value in field
OBJECTID 47has a NULL value in field
OBJECTID 88has a NULL value in field
OBJECTID 106has a NULL value in field
OBJECTID 108has a NULL value in field
OBJECTID 121has a NULL value in field
OBJECTID 130has a NULL value in field
OBJECTID 182has a NULL value in field
OBJECTID 210has a NULL value in field
OBJECTID 44has a NULL value in field
OBJECTID 47has a NULL value in field
OBJECTID 88has a NULL value in field
OBJECTID 106has a NULL value in field
OBJECTID 108has a NULL value in field
OBJECTID 121has a NULL value in field
OBJECTID 130has a NULL value in field
OBJECTID 182has a NULL value in field
OBJECTID 210has a NULL value in field&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 16:59:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204235#M65360</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-08-18T16:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Search for blank/empty and NULL records</title>
      <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204251#M65362</link>
      <description>&lt;P&gt;I was able to get what I need with the following. My only other question is how do I get the counter to on top of the OBJECTID rows?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = ["OBJECTID", "PN1"]
where = "PN1 = ' ' OR PN1 IS  NULL"
counter = 0
with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    for row in cursor:
        if row[1]in ["", " ", None]:
            counter += 1
            print ("OBJECTID {0}".format(row[0]) + "has a NULL value in field")
            
print ("{} {} records have blank/empty or NULL records".format(row[0],counter))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results;&lt;/P&gt;&lt;P&gt;OBJECTID 44has a NULL value in field&lt;BR /&gt;OBJECTID 47has a NULL value in field&lt;BR /&gt;OBJECTID 88has a NULL value in field&lt;BR /&gt;OBJECTID 106has a NULL value in field&lt;BR /&gt;OBJECTID 108has a NULL value in field&lt;BR /&gt;OBJECTID 121has a NULL value in field&lt;BR /&gt;OBJECTID 130has a NULL value in field&lt;BR /&gt;OBJECTID 182has a NULL value in field&lt;BR /&gt;OBJECTID 210has a NULL value in field&lt;BR /&gt;210 9 records have blank/empty or NULL records&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do i put the "210 9 records have blank/empty or NULL records" on top like so&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;210 9 records have blank/empty or NULL records.&lt;/P&gt;&lt;P&gt;OBJECTID 44has a NULL value in field&lt;BR /&gt;OBJECTID 47has a NULL value in field&lt;BR /&gt;OBJECTID 88has a NULL value in field&lt;BR /&gt;OBJECTID 106has a NULL value in field&lt;BR /&gt;OBJECTID 108has a NULL value in field&lt;BR /&gt;OBJECTID 121has a NULL value in field&lt;BR /&gt;OBJECTID 130has a NULL value in field&lt;BR /&gt;OBJECTID 182has a NULL value in field&lt;BR /&gt;OBJECTID 210has a NULL value in field&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 17:51:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204251#M65362</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-08-18T17:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Search for blank/empty and NULL records</title>
      <link>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204269#M65363</link>
      <description>&lt;P&gt;You could accumulate the messages in a string,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;msg = ''
count = 0
for i in range(1,10):
  count += 1
  msg = f'record {i}\n'
print("total records =", count)
print(msg)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Aug 2022 18:25:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-for-blank-empty-and-null-records/m-p/1204269#M65363</guid>
      <dc:creator>Brian_Wilson</dc:creator>
      <dc:date>2022-08-18T18:25:59Z</dc:date>
    </item>
  </channel>
</rss>

