Comparing two consecutive rows in a featureclass in a python script.

410
1
02-28-2011 03:43 AM
NeilOllerhead
New Contributor
I would like to know how I can compare data in two consecutive rows in a feature class.  I want to compare data in two consecutive rows and based on this comparison decide if I want to delete the first row in the pair. See example below.


table
-------------
          id    col_a    col_b    col_c
row-1   1      dog      red      sad
row-2   2      dog      red    happy
row-3   3      cat     black     mad


logic
-------------
a = get_first
b = get_next

for each row in table:
    if a.col_a = b.col_a:
        delete a
    a = b
    b = get_next

If I use a cursor where I say a = cur.next() and b=cur.next() they both end up pointing to the second object fetched from the cursor.  I can't seem to figure out how to peek into the next row in a table without advancing the cursor pointer.  In Oracle there are Lead / Lag functions that let you look at the next / previous rows in a table.  Any advice would be greatly appreciated.  Thanks in advance.

Neil
Tags (2)
0 Kudos
1 Reply
LoganPugh
Occasional Contributor III
Perhaps use the first loop to simply gather all the OIDs for the rows that need to be deleted and then use another loop to delete them, or use DeleteRows_management (following a MakeFeatureLayer_management with SQL expression built from the OIDs).
0 Kudos