<?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: Deleting rows in attribute table with arcpy in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347737#M75034</link>
    <description>&lt;P&gt;Thanks for your reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I haven't thought about that, thanks! However, I still get an error...&lt;/P&gt;&lt;P&gt;Did you meant something like the one below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.SelectLayerByAttribute(ALayer, "NEW_SELECTION","ToDate &amp;lt; CURRENT_DATE()")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;                              Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[58]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1&lt;/SPAN&gt;:     arcpy.management.SelectLayerByAttribute(achsenLayer, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;NEW_SELECTION&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;,&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;ToDate &amp;lt; CURRENT_DATE()&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;SelectLayerByAttribute&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;10780&lt;/SPAN&gt;: &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; e

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;SelectLayerByAttribute&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;10777&lt;/SPAN&gt;: retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;&amp;lt;lambda&amp;gt;&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;512&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;lambda&lt;/SPAN&gt; *args: val(*gp_fixargs(args, &lt;SPAN class=""&gt;True&lt;/SPAN&gt;))

&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;: Object: Error in executing tool
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;/PRE&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2023 15:48:09 GMT</pubDate>
    <dc:creator>NadjaHertel</dc:creator>
    <dc:date>2023-11-09T15:48:09Z</dc:date>
    <item>
      <title>Deleting rows in attribute table with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347641#M75025</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with ArcGIS Pro 3.0.5 and I am using a python notebook for managing my layers. One layer contains streets (old ones which are out of date and actual ones). So in the attribute table, there is a field with the ToDate for each street segment. My goal is to delet all the old street segments, however, I struggel a bit with the task.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, following the script which I have so far:&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;# Loading the libraries
import arcpy
import os
import numpy as np
import datetime

# Referencing the current project
aprx = arcpy.mp.ArcGISProject('current')

# Rerencing the appropiate map
mp = aprx.listMaps('Map')[0]

# Referencing the individual map layers in different variables
CLayer = aprx.listMaps()[0].listLayers('C-line')
ALayer = aprx.listMaps()[0].listLayers('achsen')

# Referencint the table
clsTable = aprx.listMaps()[0].listTables('CLS_Table')

# Checking the data type
print(type(clsTable))
print(type(CLayer))
print(type(ALayer))

# Printing the first rows of the table - should work similar for the other variables
with arcpy.da.SearchCursor(clsTable[0], "*") as cursor:
    # Use slicing to get the first 5 rows
    first_five_rows = [row for i, row in enumerate(cursor)][:5]

# Print the first five rows
for row in first_five_rows:
    print(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, the script is working. But now it starts:&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;# Creating a variable for the current date
cur_date = datetime.datetime.today()

# Cleaning the layer
where_clause1 = """ToDate &amp;lt; '{}'""".format(cur_date.strftime('%Y-%m-%d'))

# Selecting the rows
arcpy.Select_analysis(ALayer, "select_past_dates", where_clause1)

# Deleting the selected rows
arcpy.DeleteFeatures_management("select_past_dates")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;                              Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[8]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;5&lt;/SPAN&gt;:     arcpy.Select_analysis(ALayer, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;select_past_dates&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;, where_clause1)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\analysis.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;Select&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;138&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; e

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\analysis.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;Select&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;135&lt;/SPAN&gt;:   retval = convertArcObjectToPythonObject(gp.Select_analysis(*gp_fixargs((in_features, out_feature_class, where_clause), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;&amp;lt;lambda&amp;gt;&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;512&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;lambda&lt;/SPAN&gt; *args: val(*gp_fixargs(args, &lt;SPAN class=""&gt;True&lt;/SPAN&gt;))

&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;: Object: Error in executing tool
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I also tried it this way:&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;cursor = arcpy.da.UpdateCursor(ALayer, ["ToDate"])
for row in cursor:
    if row[0] &amp;lt; cur_date:
        cursor.deletRow()
cursor.close()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;                              Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[13]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1&lt;/SPAN&gt;:     cursor = arcpy.da.UpdateCursor(ALayer, [&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;ToDate&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;])

&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;: 'in_table' is not a table or a featureclass
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be great if someone could help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Nadja&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 13:00:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347641#M75025</guid>
      <dc:creator>NadjaHertel</dc:creator>
      <dc:date>2023-11-09T13:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting rows in attribute table with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347694#M75031</link>
      <description>&lt;P&gt;You are using the wrong Select tool, you want to be using the Select by Attributes tool.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 14:23:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347694#M75031</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2023-11-09T14:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting rows in attribute table with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347737#M75034</link>
      <description>&lt;P&gt;Thanks for your reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I haven't thought about that, thanks! However, I still get an error...&lt;/P&gt;&lt;P&gt;Did you meant something like the one below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.SelectLayerByAttribute(ALayer, "NEW_SELECTION","ToDate &amp;lt; CURRENT_DATE()")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;                              Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[58]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;1&lt;/SPAN&gt;:     arcpy.management.SelectLayerByAttribute(achsenLayer, &lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;NEW_SELECTION&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;,&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;ToDate &amp;lt; CURRENT_DATE()&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;)

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;SelectLayerByAttribute&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;10780&lt;/SPAN&gt;: &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; e

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;SelectLayerByAttribute&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;10777&lt;/SPAN&gt;: retval = convertArcObjectToPythonObject(gp.SelectLayerByAttribute_management(*gp_fixargs((in_layer_or_view, selection_type, where_clause, invert_where_clause), &lt;SPAN class=""&gt;True&lt;/SPAN&gt;)))

File &lt;SPAN class=""&gt;C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;&amp;lt;lambda&amp;gt;&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;512&lt;/SPAN&gt;:   &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;lambda&lt;/SPAN&gt; *args: val(*gp_fixargs(args, &lt;SPAN class=""&gt;True&lt;/SPAN&gt;))

&lt;SPAN class=""&gt;RuntimeError&lt;/SPAN&gt;: Object: Error in executing tool
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;/PRE&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:48:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347737#M75034</guid>
      <dc:creator>NadjaHertel</dc:creator>
      <dc:date>2023-11-09T15:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting rows in attribute table with arcpy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347740#M75035</link>
      <description>&lt;P&gt;Yes that's the correct tool, but your where clause is incorrect &lt;EM&gt;ToDate&lt;/EM&gt; is not being referenced correctly. Read the help for this tool and explore the samples to understand how to build the clause correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 15:57:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/deleting-rows-in-attribute-table-with-arcpy/m-p/1347740#M75035</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2023-11-09T15:57:55Z</dc:date>
    </item>
  </channel>
</rss>

