[GIS] How to extract certain values from a table using the SearchCursor Tool

arcgis-10.2arcgis-desktoparcpycursorpython

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 = cursor.next()
while row:
    print (row.getValue(field))
    row = cursor.next()

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

enter image description here

Best Answer

list_of_fields_with_depth = (x.name 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]
            break
        else:
            print "no zero on this line"