<?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 delete rows in feature classes where some of the fields contain zero (0) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61713#M4919</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far I got this far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&amp;nbsp; &lt;/P&gt;&lt;P&gt;from arcpy import env&amp;nbsp; &lt;/P&gt;&lt;P&gt;env.workspace = r"C:\SouthA\Bolivia.gdb"&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;listFCs = arcpy.ListFeatureClasses("*")&lt;/P&gt;&lt;P&gt;for fc in listFCs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, , , ["field1", "field2", "field6", "field7"])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.getValue() == 0:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.deleteRow(row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is that in each table select and delete the rows which have "0"s in either/or&amp;nbsp; field1, field2....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Feb 2015 13:42:25 GMT</pubDate>
    <dc:creator>ErtTre</dc:creator>
    <dc:date>2015-02-05T13:42:25Z</dc:date>
    <item>
      <title>delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61713#M4919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far I got this far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&amp;nbsp; &lt;/P&gt;&lt;P&gt;from arcpy import env&amp;nbsp; &lt;/P&gt;&lt;P&gt;env.workspace = r"C:\SouthA\Bolivia.gdb"&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;listFCs = arcpy.ListFeatureClasses("*")&lt;/P&gt;&lt;P&gt;for fc in listFCs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, , , ["field1", "field2", "field6", "field7"])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.getValue() == 0:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.deleteRow(row)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is that in each table select and delete the rows which have "0"s in either/or&amp;nbsp; field1, field2....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 13:42:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61713#M4919</guid>
      <dc:creator>ErtTre</dc:creator>
      <dc:date>2015-02-05T13:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61714#M4920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For starters, I encourage you to read up on the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/What_is_the_data_access_module/018w00000008000000/"&gt;Arcpy Data Access module (arcpy.da).&lt;/A&gt;&amp;nbsp; The cursors in the data access module are newer, more robust, and higher performing than the older cursors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I gotta step out but will post some code when I get back if someone hasn't already.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 14:48:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61714#M4920</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-05T14:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61715#M4921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Haven't tested, but try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy&amp;nbsp; 
from arcpy import env&amp;nbsp; 
env.workspace = r"C:\SouthA\Bolivia.gdb" 

listFCs = arcpy.ListFeatureClasses("*")
for fc in listFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, ["field1", "field2", "field6", "field7"]) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 in row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.deleteRow()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:20:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61715#M4921</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T22:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61716#M4922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of checking each row to see if it meets the condition, could you only bring back the rows that meet the condition and delete them all?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;arcpy.env.workspace = r&lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"C:\SouthA\Bolivia.gdb"&lt;/SPAN&gt;

listFCs = arcpy.ListFeatureClasses("*")
field_names = ["field1", "field2", "field6", "field7"]
where_clause = "field1 = 0 OR field2 = 0 OR field6 = 0 OR field7 = 0"
for fc in listFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, field_names, where_clause) as cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.deleteRow()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:20:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61716#M4922</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-10T22:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61717#M4923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is another approach.&amp;nbsp; Although I like working with SQL, building SQL expressions via Python and passing them to Esri tools seems to be a hang up for lots of folks, so I decided against suggesting a where_clause, but it will work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Feb 2015 16:57:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61717#M4923</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-05T16:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: delete rows in feature classes where some of the fields contain zero (0)</title>
      <link>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61718#M4924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both ideas worked!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Feb 2015 10:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-rows-in-feature-classes-where-some-of-the/m-p/61718#M4924</guid>
      <dc:creator>ErtTre</dc:creator>
      <dc:date>2015-02-06T10:51:09Z</dc:date>
    </item>
  </channel>
</rss>

