I need to find duplicates by comparing to fields. I am not sure how to accomplish this so any help would be appreciated.
I have two fields that i need to compare, Account and Acres1 fields. if there is not duplicate then put a "0" in the duplicate field for that record.
The end scenario i need something like this.
Account Acres Duplicate
D54963 <SPAN class="number token">12.43</SPAN> <SPAN class="number token">0</SPAN>
D54963 <SPAN class="number token">12.43</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="punctuation token">(</SPAN>duplicate<SPAN class="punctuation token">)</SPAN>
D54963 <SPAN class="number token">12.43</SPAN> <SPAN class="number token">2</SPAN> <SPAN class="punctuation token">(</SPAN>duplicate<SPAN class="punctuation token">)</SPAN>
D45879 <SPAN class="number token">26.32</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">(</SPAN>no duplicate<SPAN class="punctuation token">)</SPAN>
D45879 <SPAN class="number token">17.32</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">(</SPAN>no duplicate<SPAN class="punctuation token">)</SPAN>
D36540 <SPAN class="number token">17.51</SPAN> <SPAN class="number token">0</SPAN>
D36540 <SPAN class="number token">17.51</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="punctuation token">(</SPAN>duplicate<SPAN class="punctuation token">)</SPAN>
D36540 <SPAN class="number token">17.51</SPAN> <SPAN class="number token">2</SPAN> <SPAN class="punctuation token">(</SPAN>duplicate<SPAN class="punctuation token">)</SPAN>
D36540 <SPAN class="number token">17.51</SPAN> <SPAN class="number token">3</SPAN> <SPAN class="punctuation token">(</SPAN>duplicate<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I have the following code but it only checks one field (Account) and it add a number to all attributes if there is a double not exactly what i need.
<SPAN class="keyword token">import</SPAN> arcpy
infeature <SPAN class="operator token">=</SPAN><SPAN class="string token">"C:/Temp/Test_FINAL_Erase"</SPAN>
field_in <SPAN class="operator token">=</SPAN><SPAN class="string token">"Account"</SPAN>
field_out <SPAN class="operator token">=</SPAN><SPAN class="string token">"COUNT_"</SPAN><SPAN class="operator token">+</SPAN>field_in
<SPAN class="comment token">#create the field for the count values</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>infeature<SPAN class="punctuation token">,</SPAN>field_out<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"SHORT"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#creating the list with all the values in the field, including duplicates</SPAN>
lista<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
cursor1<SPAN class="operator token">=</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>infeature<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor1<SPAN class="punctuation token">:</SPAN>
i<SPAN class="operator token">=</SPAN>row<SPAN class="punctuation token">.</SPAN>getValue<SPAN class="punctuation token">(</SPAN>field_in<SPAN class="punctuation token">)</SPAN>
lista<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> cursor1<SPAN class="punctuation token">,</SPAN> row
<SPAN class="comment token">#updating the count field with the number on occurrences of field_in values</SPAN>
<SPAN class="comment token">#in the previously created list</SPAN>
cursor2<SPAN class="operator token">=</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>infeature<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor2<SPAN class="punctuation token">:</SPAN>
i<SPAN class="operator token">=</SPAN>row<SPAN class="punctuation token">.</SPAN>getValue<SPAN class="punctuation token">(</SPAN>field_in<SPAN class="punctuation token">)</SPAN>
occ<SPAN class="operator token">=</SPAN>lista<SPAN class="punctuation token">.</SPAN>count<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN>
row<SPAN class="punctuation token">.</SPAN>setValue<SPAN class="punctuation token">(</SPAN>field_out<SPAN class="punctuation token">,</SPAN>occ<SPAN class="punctuation token">)</SPAN>
cursor2<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> cursor2<SPAN class="punctuation token">,</SPAN> row
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Done."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>