I have dataset that has columns that need to be sorted based on multiple columns.
The first column contains a name and the second a number, the names are not unique. What I want is a NewID from 1 to 10 per name based on the descending value of the number. Like this: example
Any ideas how this can be done? Preferably in ArcMap.
-
Do you need a python script or step by step algorithm as an answer?Comrade Che– Comrade Che2017年05月12日 10:20:49 +00:00Commented May 12, 2017 at 10:20
-
Python script that can be used in field calculator would be nice.Michiel– Michiel2017年05月12日 10:24:08 +00:00Commented May 12, 2017 at 10:24
-
1ArcMap and FME require different solutions, which makes this question too broad. A Python solution requires you to provide the code you've developed to date. Please Edit the question.Vince– Vince2017年05月12日 10:35:41 +00:00Commented May 12, 2017 at 10:35
-
I removed FME, I currently do not have a python script.Michiel– Michiel2017年05月12日 11:23:54 +00:00Commented May 12, 2017 at 11:23
2 Answers 2
I know you removed FME but for the record, a Sorter, sorting by the NameID and then secondly the number, followed by a Counter with the Counter ID set to the value of the NameID attribute will do exactly what you want.
This is will not answer your question but it might help you to solve your problem. Here is how to sort lists in python:
import pprint
table = [
[1,'H',-1],
[2,'D',2],
[3,'D',8],
[4,'D',1],
[5,'H',68],
[6,'H',97],
[7,'H',88],
]
print 'Before sorting:'
print '[OBJECTID, NameID, Number]'
pprint.pprint(table)
print
print 'After sorting:'
print '[OBJECTID, NameID, Number]'
pprint.pprint(
sorted(table, key=lambda x: (x[1], x[2]))
)
Excetuting this script gives:
Before sorting:
[OBJECTID, NameID, Number]
[[1, 'H', -1],
[2, 'D', 2],
[3, 'D', 8],
[4, 'D', 1],
[5, 'H', 68],
[6, 'H', 97],
[7, 'H', 88]]
After sorting:
[OBJECTID, NameID, Number]
[[4, 'D', 1],
[2, 'D', 2],
[3, 'D', 8],
[1, 'H', -1],
[5, 'H', 68],
[7, 'H', 88],
[6, 'H', 97]]
Explore related questions
See similar questions with these tags.