Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a python script to extract certain values from a table: the table I am referring to is a big collection of nitrate values for different water depths, which are deposited in the columns of the table. As I only need the value of the surface and the deepest point, I want to search through the rows and extract the last value that is not 0. I have started writing a script using the SearchCursor Tool but get stuck at the point, where I want it to search for the first 0-value and then go back and print the value fro mthe column before... Does anyone have an idea how to solve that problem?

import arcpy

# Set the Workspace
arcpy.env.workspace = "D:\Teresa\Kerstin\SouthernOcean\03_workspace\Teresa"

# Make table
table = "C:/Users/theidema/Desktop/OxzUti_GridP_Annual.csv"

#Create the search cursor
cursor = arcpy.SearchCursor(Table)

#Iterate through the rows
row =
while row:
    print (row.getValue(field))
    row =

Here is a Screenshot of the table (depths go down until 5500M)

enter image description here

share|improve this question
Teresa, what is your version of ArcGIS? – Alex Tereshenkov Aug 19 '14 at 7:41
could you please add an view of your table to illustrate your problem? I don't understand if you need to iterate on the columns or on the rows. What version of ArcGIS are you using ? – radouxju Aug 19 '14 at 7:46
I am using the 10.2.1. Version! – Teresa Heidemann Aug 19 '14 at 8:20
You may want to think about using Summary Statistics (MAX—Finds the largest value for all records of the specified field) rather than ArcPy to get this but I am not 100% clear on your requirements. – PolyGeo Aug 19 '14 at 8:46
up vote 2 down vote accepted
list_of_fields_with_depth = ( for x in arcpy.Listfields(Table, "wildcard"))
cursor = arcpy.da.SearchCursor(Table, list_of_fields_with_depth)

#Iterate through the rows

for row in rows:
    for i in range(len(list_of_fields_with_depth)):
        if ( (row[i] == 0) and (i>0) ):
            print row[i-1]
            print "no zero on this line" 
share|improve this answer
Thanks alot!! Its working now! – Teresa Heidemann Aug 19 '14 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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