4

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

4
  • 1
    Teresa, what is your version of ArcGIS? Commented Aug 19, 2014 at 7:41
  • 1
    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 ? Commented Aug 19, 2014 at 7:46
  • I am using the 10.2.1. Version! Commented Aug 19, 2014 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. Commented Aug 19, 2014 at 8:46

1 Answer 1

2
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" 
0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.