Skip to main content
added 32 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

Create two lists, one with even and one with odd numbers. Then sort each and combine. I copy-pasted your data into a csv file.

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable) #Create table from view
arcpy.TruncateTable_management(os.path.join(outdb,outtable)) #Empty it

fields = ['Layer','Meas', 'ID']
 
icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)
     
rows = [i for i in arcpy.da.SearchCursor('tview', fields)] #List all rows
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even Layer numbers (Layer is first element in fields list = index[0]
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0]) 

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)
for row in both:
    icur.insertRow(row)

del icur

enter image description here

Create two lists, one with even and one with odd numbers. Then sort each and combine. I copy-pasted your data into a csv file.

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable)
arcpy.TruncateTable_management(os.path.join(outdb,outtable))

fields = ['Layer','Meas', 'ID']
 
icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)

rows = [i for i in arcpy.da.SearchCursor('tview', fields)]
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even numbers
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0])

for row in both:
    icur.insertRow(row)

del icur

enter image description here

Create two lists, one with even and one with odd numbers. Then sort each and combine. I copy-pasted your data into a csv file.

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable) #Create table from view
arcpy.TruncateTable_management(os.path.join(outdb,outtable)) #Empty it

fields = ['Layer','Meas', 'ID']
        
rows = [i for i in arcpy.da.SearchCursor('tview', fields)] #List all rows
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even Layer numbers (Layer is first element in fields list = index[0]
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0]) 

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)
for row in both:
    icur.insertRow(row)

del icur

enter image description here

added 41 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

Create two lists, one with even and one with odd numbers. Then sort each and combine:. I copy-pasted your data into a csv file.

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable)
arcpy.TruncateTable_management(os.path.join(outdb,outtable))

fields = ['Layer','Meas', 'ID']

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)

rows = [i for i in arcpy.da.SearchCursor('tview', fields)]
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even numbers
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0])

for row in both:
    icur.insertRow(row)

del icur

enter image description here

Create two lists, one with even and one with odd numbers. Then sort each and combine:

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable)
arcpy.TruncateTable_management(os.path.join(outdb,outtable))

fields = ['Layer','Meas', 'ID']

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)

rows = [i for i in arcpy.da.SearchCursor('tview', fields)]
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even numbers
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0])

for row in both:
    icur.insertRow(row)

del icur

enter image description here

Create two lists, one with even and one with odd numbers. Then sort each and combine. I copy-pasted your data into a csv file.

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable)
arcpy.TruncateTable_management(os.path.join(outdb,outtable))

fields = ['Layer','Meas', 'ID']

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)

rows = [i for i in arcpy.da.SearchCursor('tview', fields)]
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even numbers
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0])

for row in both:
    icur.insertRow(row)

del icur

enter image description here

Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 187

Create two lists, one with even and one with odd numbers. Then sort each and combine:

import arcpy, os

testfile = r"C:\GIS\data\testdata\sortme.csv"
outdb = r"C:\GIS\data\testdata\testdatabas.gdb"
outtable = 'sorted2'

arcpy.MakeTableView_management(in_table=testfile, out_view='tview')
arcpy.TableToTable_conversion(in_rows='tview', out_path=outdb, out_name=outtable)
arcpy.TruncateTable_management(os.path.join(outdb,outtable))

fields = ['Layer','Meas', 'ID']

icur = arcpy.da.InsertCursor(os.path.join(outdb,outtable), fields)

rows = [i for i in arcpy.da.SearchCursor('tview', fields)]
even = list(filter(lambda x: (x[0]%2==0), rows)) #filter out even numbers
odd = list(filter(lambda x: (x[0]%2!=0), rows)) #odd

even_sorted  = sorted(even, key=lambda x: x[1], reverse=True)
odd_sorted  = sorted(odd, key=lambda x: x[1])
both = sorted(even_sorted+odd_sorted, key=lambda x: x[0])

for row in both:
    icur.insertRow(row)

del icur

enter image description here