How to do a Column Calculation using multiple rows with some empty cells

Hi I am trying to calculate the difference between two rows within a column using python and then insert it into a table.  My problem is that I have empty cells (that i need to remain in place. I have included an example of a script i have tried but get a index out of range error.  I have also tried "try and except" commands in my scripts but ran into similar errors. Im very new to python and spotfire and would greatly appreciate the help!

A B Calculation
1 1 =1-0
1 3 =3-1
1 8 =8-2
1   leave blank OR set to -999.25
2 4 4-0
2 6 6-4
2 9 9-6
2 14 14-9
2 19 19-14
from Spotfire.Dxp.Data import *
from System.Collections.Generic import List

#get the data table
table=Document.Data.Tables["LAS OnDemand"]

#place generic data cursor on a specific column
cursor = DataValueCursor.CreateFormatted(table.Columns["B"])

#list object to store retrieved values
valData = List [str]();


#iterate through table column rows to retrieve the values
for row in table.GetRows(cursor):
	value = cursor.CurrentValue
	if value <> str.Empty:
		valData.Add(value)	

diff = []

for i in range(len(valData)-1):	
	if valData[i].isdigit():
		a= float (valData[i])
	else:
		a=-999.25
	if valData[i+1].isdigit():
		b= float (valData[i+1])
	else:
		b=-999.25
	diff[i]=b-a

 

(1) Answer

Login