<?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: Get Count While Applying a filter in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117879#M9254</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Christina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you need is the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006p000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Make Feature Layer method&lt;/A&gt;&lt;SPAN&gt;. It works almost identically to Select By Attribute in ArcMap or ArcCatalog: it will use the filter and generate a layer of features that satisfied the filter condition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;filter = "\"FACILITY_I\" = ' '"
shp = r"C:\Users\gisadmin\Desktop\TEST\FH_Test.shp"
lyr = arcpy.MakeFeatureLayer(shp, filter)
result = int(arcpy.GetCount_management(lyr).getOutput(0))
print result&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And your output can go wherever you want, depending on what format you're looking at. To write it to a table, you could use a Cursor object. If you're writing it to a table in a textfile or CSV, you could write it using Python's builtin open function. With a little more information, this shouldn't be hard to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:55:00 GMT</pubDate>
    <dc:creator>MarcNakleh</dc:creator>
    <dc:date>2021-12-11T06:55:00Z</dc:date>
    <item>
      <title>Get Count While Applying a filter</title>
      <link>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117878#M9253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I hope this is something easy to do, although I can't find the right formula to make this work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to run a filter on a table to find features who have a specific field blank. I ultimately want to output that count of features out to a text file. The trouble I am having is that GetCount_management does not work correctly when I try and apply a filter to it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Right now I have ..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;filter = "\"FACILITY_I\" = ' '"
lyr = "C:\\Users\\gisadmin\\Desktop\\TEST\\FH_Test.shp"
result = int(arcpy.GetCount_management(lyr).getOutput(0))
print result 
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and that works .. but it's (obviously) giving me the total since the filter is not referenced in at all. When I try and build a filter in I start getting errors, typically Runtime errors in executing tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does someone know how to run this function while applying a filter, or another way to accomplish the same goal? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, as opposed to printing the results to a screen I'd like to write them to a table, however I'm moving from vB into Python so I'm still learning the language. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice or help would be greatly appreciated. Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:36:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117878#M9253</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2011-10-14T13:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count While Applying a filter</title>
      <link>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117879#M9254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Christina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you need is the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006p000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Make Feature Layer method&lt;/A&gt;&lt;SPAN&gt;. It works almost identically to Select By Attribute in ArcMap or ArcCatalog: it will use the filter and generate a layer of features that satisfied the filter condition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;filter = "\"FACILITY_I\" = ' '"
shp = r"C:\Users\gisadmin\Desktop\TEST\FH_Test.shp"
lyr = arcpy.MakeFeatureLayer(shp, filter)
result = int(arcpy.GetCount_management(lyr).getOutput(0))
print result&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And your output can go wherever you want, depending on what format you're looking at. To write it to a table, you could use a Cursor object. If you're writing it to a table in a textfile or CSV, you could write it using Python's builtin open function. With a little more information, this shouldn't be hard to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:55:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117879#M9254</guid>
      <dc:creator>MarcNakleh</dc:creator>
      <dc:date>2021-12-11T06:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count While Applying a filter</title>
      <link>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117880#M9255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your help so far! Luckily it's not erroring out on the filter, however it's not acknowledging it either. On this test set I still get 89 no matter what. I've even tried altering the filter to make sure it wasn't incorrectly typed but that is not helping.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway I have it not erroring and now printing to the test file, so if I can figure out how to get the filter to work then I'll be set! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 14:10:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117880#M9255</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2011-10-14T14:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count While Applying a filter</title>
      <link>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117881#M9256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found the tweak I needed. Thank you for your help!! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;shp = r"C:\Users\gisadmin\Desktop\TEST\FH_Test.shp"
filter = "\"FACILITY_I\" = ' '"
lyr = arcpy.MakeFeatureLayer_management(shp, "FH_Test_lyr", filter)
result = int(arcpy.GetCount_management(lyr).getOutput(0))
outtable.write(str(result))
print result
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:55:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-while-applying-a-filter/m-p/117881#M9256</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2021-12-11T06:55:03Z</dc:date>
    </item>
  </channel>
</rss>

