<?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: How to delete duplicate rows where multiple values are duplicated? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35439#M2759</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you want to call deleteRow() rather than del &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;rowsToDelete, which just deletes the Python variable called "rowsToDelete".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;... upd_cur = arcpy.da.UpdateCursor(in_table,fields,where_clause)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;... &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; row &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; upd_cur:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background-color: inherit; color: #006699; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt;upd_cur.deleteRow() # Beware: deletes the current row&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:23:01 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-10T21:23:01Z</dc:date>
    <item>
      <title>How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35438#M2758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;I have a feature class where there are multiple values duplicated in a row, i.e. SRNumber and RESOLUTION_CODE. I would like to delete all rows where my SRNumber and RESOLUTION_CODE are found in multiple rows. I have got a good start with this script, everything works aside from actually deleting the rows. How can I fix this so that my duplicate rows are deleted?&lt;/P&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;So if &lt;CODE&gt;SRNumber = 1-23456&lt;/CODE&gt; and &lt;CODE&gt;Resolution_Code = 'A'&lt;/CODE&gt; and appears twice, I would like to delete one.&lt;/P&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;I have taken this example for GIS Stackexchange, but the del rows does not work correctly.&lt;/P&gt;&lt;P style="margin-bottom: 1em; font-size: 15px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgba(248, 248, 248, 0.6);"&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
... 
... in_table = r"ServiceRequest.DBO.SO_Dead_Animal"
... fields = ["NumberCYLA","RESOLUTION_CODE"] #replace with own
... curStrings = arcpy.da.SearchCursor(in_table,fields,"NumberCYLA is not null")
... 
... stringsKeysList = []
... numbersValuesList = []
... tableDict = {}
... 
... for row in curStrings: 
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0],row[1]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringsKeysList.append(row[0])
... del curStrings
... uniqueStringsList = list(set(stringsKeysList)) #only unique values from Strings field
... 
... for uniqueString in uniqueStringsList:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; emptyTempValues = []
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curValues = arcpy.da.SearchCursor(in_table,fields,"""NumberCYLA = '{0}'""".format(str(uniqueString)))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curValues:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; emptyTempValues.append(row[1])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uniqueEmptyTempValues = list(set(emptyTempValues))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tableDict[uniqueString] = uniqueEmptyTempValues
... 
... print tableDict
... 
... rowsToDelete = [k for k, v in tableDict.iteritems() if v == [-1]] #find which rows to delete
... print "list: ", rowsToDelete
... stringRows = ","
... updRows = stringRows.join(rowsToDelete)
... updRows = updRows.replace(",","','")
... print updRows #update the string to be used with proper syntax in where clause
... 
... where_clause = """NumberCYLA in ('{0}')""".format(updRows)
... upd_cur = arcpy.da.UpdateCursor(in_table,fields,where_clause)
... for row in upd_cur:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0],row[1]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del rowsToDelete&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:22:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35438#M2758</guid>
      <dc:creator>GeoffreyWest</dc:creator>
      <dc:date>2021-12-10T21:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35439#M2759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you want to call deleteRow() rather than del &lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;rowsToDelete, which just deletes the Python variable called "rowsToDelete".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;... upd_cur = arcpy.da.UpdateCursor(in_table,fields,where_clause)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;... &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; row &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; upd_cur:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="background-color: inherit; color: #006699; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt;upd_cur.deleteRow() # Beware: deletes the current row&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:23:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35439#M2759</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-10T21:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35440#M2760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also just run the Delete Identical tool under Data Management, General. A whole lot easier. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 19:16:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35440#M2760</guid>
      <dc:creator>JustinHollenbach1</dc:creator>
      <dc:date>2015-08-13T19:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35441#M2761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to clarify the problem you are trying to solve...if this is your attribute table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="169" style="border: 1px solid rgb(198, 198, 198); width: 500px; height: 138px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; color: rgb(80, 80, 80); padding: 6px; background-color: rgb(242, 242, 242);" valign="middle"&gt;&lt;STRONG&gt;OBJECTID*&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; color: rgb(80, 80, 80); padding: 6px; background-color: rgb(242, 242, 242);" valign="middle"&gt;&lt;STRONG&gt;NumberCYLA&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; color: rgb(80, 80, 80); padding: 6px; background-color: rgb(242, 242, 242);" valign="middle"&gt;&lt;STRONG&gt;SRNumber&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; color: rgb(80, 80, 80); padding: 6px; background-color: rgb(242, 242, 242);" valign="middle"&gt;&lt;STRONG&gt;Resolution_Code&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="text-align: center;"&gt;11&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;1-23456&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;22&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;1-9987&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="text-align: center;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;33&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;1-23456&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;A&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;44&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;1-5555&lt;/TD&gt;&lt;TD style="padding: 6px; text-align: center;"&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...you would want the 3rd row deleted because it is a duplicate of row 1 (&lt;EM&gt;SRNumber&lt;/EM&gt; and &lt;EM&gt;Resolution_Code&lt;/EM&gt; match), correct?&amp;nbsp; The code sample you grabbed is not particularly readable (to me) so I just wanted to make sure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, is the field &lt;EM&gt;NumberCYLA&lt;/EM&gt; a &lt;STRONG&gt;unique identifier&lt;/STRONG&gt; for your feature class?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 19:18:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35441#M2761</guid>
      <dc:creator>AdamMarinelli</dc:creator>
      <dc:date>2015-08-13T19:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35442#M2762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just FYI, Delete Identical requires advanced licensing, while this script requires none.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 21:02:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35442#M2762</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-08-13T21:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35443#M2763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Adam Marinelli, that is correct, it should be mentioned that NUMBERCYLA and SRNumber are identical.&amp;nbsp; But your example is correct, if I have one Service Request number repeated at different objectIDs, I would like to remove one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2015 03:43:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35443#M2763</guid>
      <dc:creator>GeoffreyWest</dc:creator>
      <dc:date>2015-08-14T03:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35444#M2764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have the proper licensing then definitely use &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/delete-identical.htm"&gt;Delete Identical&lt;/A&gt; as &lt;A href="https://community.esri.com/migrated-users/133925"&gt;Justin Hollenbach&lt;/A&gt;​ suggested....there is a tool for everything!&amp;nbsp; Otherwise, here is a much simpler python script which should do what you need.&amp;nbsp; I haven't tested it with a very large feature class so performance could be an issue depending on the # of records in your input datasets.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2015 16:19:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35444#M2764</guid>
      <dc:creator>AdamMarinelli</dc:creator>
      <dc:date>2015-08-14T16:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete duplicate rows where multiple values are duplicated?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35445#M2765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The performance of the script can be improved by cutting out the search cursor loop.&amp;nbsp; All of the functional code works within a single update cursor:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
fc = #full path to feature class
fields = ['OBJECTID', 'SRNumber', 'Resolution_Code']

table_rows = []
with arcpy.da.UpdateCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[1:] in table_rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Deleting record: OBJECTID = {}".format(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.deleteRow()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table_rows.append(row[1:])
del table_rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-delete-duplicate-rows-where-multiple-values/m-p/35445#M2765</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T21:23:03Z</dc:date>
    </item>
  </channel>
</rss>

