|
POST
|
https://support.esri.com/en/technical-article/000023355 I want to improve on the above script from ESRI that finds duplicate values and writes the values to a new field in a table. It's using an old cursor and it is very slow with large datasets. But, I'm running into problems due to lack of experience. Their code verbatim for my purposes: import arcpy
'''
This script will count the number of occurences of a value in a field ("field_in") and write them to a new field ("field_out")
'''
#path to GDB goes here
arcpy.env.workspace = r"C:\pathto\DuplicateTesting.gdb\DuplicateTesting"
#name of feature class goes here
infeature = "backup_02232021"
field_in = "name"
field_out = "COUNT_"+field_in
arcpy.AddField_management(infeature, field_out,"SHORT")
lista= []
cursor1=arcpy.SearchCursor(infeature)
for row in cursor1:
i=row.getValue(field_in)
lista.append(i)
del cursor1, row
cursor2=arcpy.UpdateCursor(infeature)
for row in cursor2:
i=row.getValue(field_in)
occ=lista.count(i)
row.setValue(field_out, occ)
cursor2.updateRow(row)
del cursor2, row The following is as far as I got with my improvement. It's throwing an error on the line with the i variable. How can I continue with the UpdateCursor method to put the count of each item in the fields list into its corresponding new field? infeature = r"C:pathto\DuplicateTesting.gdb\DuplicateTesting
fields = ["name", "location_string_output", "email_address", "cell_phone_number",
"home_phone_number"]
for field_out in fields: #add new fields
arcpy.AddField_management(infeature, "COUNT_"+field_out,"SHORT")
list= []
with arcpy.da.SearchCursor(infeature, fields) as cursor1:
for row in cursor1:
list.append(row)
del cursor1, row
with arcpy.da.UpdateCursor(infeature, fields) as cursor2:
for row in cursor2:
i = row.getValue(row) #<-- throws AttributeError here
occ = list.count(i)
print(occ)
del cursor2, row Error: Traceback (most recent call last):
File "\\gisfile\GISstaff\Jared\Python Scripts\ArcGISPro\DuplicateFields_updated.py", line 21, in <module>
i = row.getValue(row)
AttributeError: 'list' object has no attribute 'getValue'
... View more
02-25-2021
09:17 AM
|
0
|
18
|
8792
|
|
POST
|
Thanks for the reply about using numpy. I'm not that advanced yet, but i'll earmark the post.
... View more
02-24-2021
12:41 PM
|
0
|
0
|
865
|
|
POST
|
Apparently, I'm braindead? I guess they were the aliases... whoops.
... View more
02-24-2021
12:33 PM
|
1
|
0
|
4410
|
|
POST
|
This is from the table. I copied the field name directly from the table and pasted into my list.
... View more
02-24-2021
12:32 PM
|
0
|
1
|
4417
|
|
POST
|
The weird thing is, these are unmistakably the fieldnames. This feature class was created by Survey123 Connect. And, I can't change them as they're part of a live survey.
... View more
02-24-2021
10:41 AM
|
0
|
5
|
4425
|
|
POST
|
Thanks for the replies! I didn't even notice I was using the old cursor (was in a rush). So, now that I'm revamping this code, I'm suck with an error : infeature = r"C:pathtofile\file.gdb\file" #name of feature class goes here
fields = ["Name:", "Location", "Email Address", "Cell Phone Number:",
"Home Phone Number:"]
with arcpy.da.SearchCursor(infeature, fields) as cursor1:
for row in cursor1:
print(row) Traceback (most recent call last):
File "\pathto\DuplicateFields_updated.py", line 18, in <module>
for row in cursor:
RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID,Name:,Location,Email Address,Cell Phone Number:,Home Phone Number: FROM backup_02232021_NEW] I'm using the fieldnames, not the aliases. Because they're strings, I don't believe the spaces matter?
... View more
02-24-2021
08:39 AM
|
0
|
7
|
4438
|
|
POST
|
I'm using the How to identify duplicate or unique values in Pro code provided by ERSI verbatim, and I'm getting an error. I have a feature class table that I'm looking for duplicates in. The technical document doesn't say whether to use the field name or alias, so I tried both. When I run it with the field name the code throws an exception. I stopped the script and opened Pro. The field gets created in the table but it's all NULLs. This is the line where the exception is being thrown: i=row.getValue(field_in) Exception/Error: Message=ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Source=\\GISFILE\GISSTAFF\Jared\Python Scripts\ArcGISPro\DuplicateFields.py
StackTrace:
File "\\GISFILE\GISSTAFF\Jared\Python Scripts\ArcGISPro\DuplicateFields.py", line 17, in <module>
i=row.getValue(field_in) When I run it with the alias it doesn't finish, or at least I've never let it because it's taking a remarkably long time. However, if I stop the script and open Pro to view the table, a lot of the 190K+ fields are written to. But, like I said it never finishes... Code: import arcpy
'''
This script will count the number of occurences of a value in a field ("field_in") and write them to a
new field ("field_out")
'''
arcpy.env.workspace = r"C:\Users\jpilbeam\Downloads\DuplicateTesting.gdb\DuplicateTesting.gdb" #path to GDB goes here
infeature = "backup_02232021" #name of feature class goes here
field_in = "name" #this is the alias of the field. Name: is the actual name
field_out = "COUNT_"+field_in
arcpy.AddField_management(infeature, field_out,"SHORT")
lista= []
cursor1=arcpy.SearchCursor(infeature)
for row in cursor1:
i=row.getValue(field_in) #<-- where exception is thrown using field name in field_in variable
lista.append(i)
del cursor1, row
cursor2=arcpy.UpdateCursor(infeature)
for row in cursor2:
i=row.getValue(field_in)
occ=lista.count(i)
row.setValue(field_out, occ)
cursor2.updateRow(row)
del cursor2, row
print("----done----") EDIT: Using the alias, I let the code run for like 15-20 mins and it finished with no errors! So, I guess it just needs that long with all these records?
... View more
02-23-2021
09:07 AM
|
0
|
11
|
5402
|
|
POST
|
Hi@Danielle_Journey , I never actually used the citizen problem reporter to its fullest as it's too confusing. I simply open the files from the ServiceSupport folder in a text editor as I need them. But, I would say create another field and then reference that field with a similar query. Sorry I couldn't be more helpful.
... View more
01-19-2021
11:12 AM
|
0
|
1
|
4840
|
|
POST
|
Chris, Not sure about your first question because I have an administrative role in AGOL. For that matter, it could have been me. As Phillip was saying, I was actually changing the sharing settings in the hosted feature layer when I was trying to correct the error. So, maybe it was me who reset the check boxes? Thanks for making me aware.
... View more
01-15-2021
08:52 AM
|
2
|
0
|
8464
|
|
POST
|
Chris, I didn't think I'd be reporting back so soon. But, when I opened a survey today I got the error again. Out of the blue, the share box on the Collaborate page of the Survey 123 website was magically unchecked. So, I clicked the box to share publicly again and it's fine. Is this a bug?
... View more
01-14-2021
10:04 AM
|
1
|
0
|
14866
|
|
POST
|
No clue what happened there. I accessed the Survey123 website through the link in the Survey123 Connect app and under Collaborate it was set to organization still. So, I set it to public and now the error is gone. Funny, I already had it set to public, as I said. I access the Survey123 website from a bookmark on my toolbar in FireFox, so maybe it was a browser/cookies issue.
... View more
01-13-2021
11:13 AM
|
1
|
2
|
14880
|
|
POST
|
Sorry, forgot to mention I created the survey with Survey 123 Connect. And the form is meant for web format only. I did happen to forget to share publicly on the Collaborate page of the survey. But, after setting that to public I still get the error. I don't want this hosted feature layer to be public, and I have view for it. I swear I've had no problems doing this workflow before.
... View more
01-13-2021
07:26 AM
|
0
|
3
|
14892
|
|
POST
|
I can not find a help document for this error. This is from a survey on the web and it does not have an error if I open it while signed in to AGOL. But, when anyone else opens it they can not submit a survey. It is a public survey. The form is shared publicly. When I submit a Complaints Form survey it is added to the Complaints Form feature layer. So, the feature service exists, but it's not shared publicly. How is it not accessible, as the error suggests?
... View more
01-12-2021
02:19 PM
|
1
|
27
|
21732
|
|
POST
|
Josh, Like you pointed out, if I have the name of the first geopoint in the calculation of the second, a point is placed in the map. However, it doesn't zoom in. Also, since I'm doing a reverse geocode the address of the first geopoint is put in the text box of the second. This: gets me this: When I remove the name of the geopoint from the calculation field, I no longer get the simultaneous point in the second map. But, I do have the reverse geocode working properly. This: gets me this:
... View more
01-08-2021
09:27 AM
|
0
|
0
|
2397
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-25-2026 12:25 PM | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
Friday
|