Select to view content in your preferred language

Sorting attribute tables by Python

6839
11
Jump to solution
01-03-2016 02:51 PM
CemAkkus2
Deactivated User

Hello there!

In new ArcGIS version, sorting is now limited to 1 field. I don't have an advanced license and I need to sort my attribute table based on 2 fields. I was wondering if there is a python script for 2 field sort.

Thanks!

Cem

0 Kudos
1 Solution

Accepted Solutions
WesMiller
Deactivated User

You could also use Sort—Help | ArcGIS for Desktop if you desire to create a copy of the table that is sorted by multiple fields.

View solution in original post

11 Replies
DanPatterson_Retired
MVP Emeritus

Sorting records in a table by multiple fields—Help | ArcGIS for Desktop  this doesn't work?  And of course sorts aren't permanent in any event

CemAkkus2
Deactivated User

Thanks for the reply Dan,

I forgot to mention that I need to sort the table permanently. The method you mention is a temporary sort so it does not change the table's original order.

Best,
Cem

WesMiller
Deactivated User

You could also use Sort—Help | ArcGIS for Desktop if you desire to create a copy of the table that is sorted by multiple fields.

CemAkkus2
Deactivated User

Thanks for the reply Wes,

I found that page after I posted. However, there is still a problem with "Python Window" version. I get this warning:

Runtime error  Traceback (most recent call last):   File "<string>", line 6, in <module>   File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 4351, in Sort     raise e ExecuteError: ERROR 000824: The tool is not licensed.

>>>

It seems ArcGIS requires Advanced License for advance permanent sorting in ArcGIS environment. However, I tested stand-alone Python script version and finally that one worked well.

Best,

Cem

WesMiller
Deactivated User

Yes to sort by shape or multiple fields requires an Advanced license see below.

License:

For the Field(s) parameter, sorting by the Shape field or by multiple fields is only available with anAdvanced license. Sorting by any single attribute field (excluding Shape) is available at all license levels.

0 Kudos
DanPatterson_Retired
MVP Emeritus

ahhhh, but then there is numpy

WesMiller
Deactivated User

I'm waiting for you to open the group

0 Kudos
CemAkkus2
Deactivated User

However, advanced sort still doable with stand-alone python script without advanced license.. which is good

0 Kudos
WesMiller
Deactivated User

Just so you are aware. It is likely that you have a license manager and an Advanced license is available when you run your python script. I am unable to locate the documentation to support this,but I've read that  arcpy gets the highest license available unless you explicitly set the license.

0 Kudos