I am very new to ArcGis and I would like to get a specific value of the previous row in a table.

I found this question here on gis.stackexchange.com and experimented a little bit. However, I found out this modified version:

Pre-Logic Script Code:

import arcpy

def getLastASTDate(tableName):
    return [r[0] for r in arcpy.da.SearchCursor(tableName, "date")][-1]

test =


Unfortunately this version doesn’t work and is -- in my opinion -- very inefficient. Do you know any better solutions?

  • 1
    I've marked this as a duplicate because the Q&A linked to describes a more efficient method to do this by using Python dictionaries. Whether this is the "most efficient" is unanswerable because someone in the future may come up something more efficient again than that.
    – PolyGeo
    Jul 29 '15 at 7:47
  • @PolyGeo: I see :) You are right :D Thanks for your replay!
    – elegent
    Jul 29 '15 at 7:50

You want to be using dictionaries to answer this question. The answer in How to access adjacent rows will help you.

To be able to answer your question you need to be supplying the row ID of the row you want to find the previous row from, my question is how are you defining that?

  • Thank you very much for your quick response! As I said I am new to ArcGis, so I am going to export the table and run a pure python script to get the data I want :) BTW: sorry for my English.
    – elegent
    Jul 28 '15 at 9:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.