I'd like to be able to use an update cursor to go through rows in a table, holding onto the previous rows value, and comparing it to the current row value, to populate a new field with this value. Does anyone know if it is possible to carry values forward to the next iteration of a loop while using an update cursor and what would this look like in code?

  • 1
    Can you give a little more detail about what you're trying to accomplish? What is the relationship between the rows you want to compare? If they're adjacent, then you can simply store the row in a variable, proceed to the next row, then access anything you need from the variable.
    – Evan
    Jun 1, 2016 at 15:02
  • 1
    Could you provide with a sample of the code you've tried?
    – Tom
    Jun 1, 2016 at 16:00

1 Answer 1


Set your row values to a different variable and proceed with your next iteration.

lastRow = None

with arcpy.da.UpdateCursor (fc, [field1, field2, field3]) as cursor:
    for row in cursor:
        if lastRow:
            ###perform comparision/calculation between lastRow and row
        lastRow = row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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