Python question: How do I iterate to the maximum value of one of my columns?

Using the Script Console,
When I ran this code:

# Create a Python dictionary of parameters to pass.
params = {"fromDate":'2022-12-20 5:15:00', "toDate":'2022-12-20 13:15:00', "tool":"minical02"}  
# Run the Named Query.
table = system.db.runNamedQuery("MiniCal_FaultCodes", params)
value = system.dataset.toPyDataSet(table) #Don't need this: 
for row in value:
	print row[0], row[1], row[2], row[3], row[4]

I get this :
0.0 1.0 0.0 1.0 1
1.0 0.0 2.0 0.0 2
0.0 10.0 2.0 0.0 3
0.0 0.0 1.0 6.0 4
5.0 4.0 5.0 1.0 5
0.0 0.0 0.0 2.0 7

I am missing the 6 in my row[4], Therefore, I would like to include this in my dataset:
0.0 0.0 0.0 0.0 6
So in the end, I end up having a complete set like this:

0.0 1.0 0.0 1.0 1
1.0 0.0 2.0 0.0 2
0.0 10.0 2.0 0.0 3
0.0 0.0 1.0 6.0 4
5.0 4.0 5.0 1.0 5
0.0 0.0 0.0 0.0 6
0.0 0.0 0.0 2.0 7

So far, this is what I've tried:

# Create a Python dictionary of parameters to pass.
params = {"fromDate":'2022-12-20 5:15:00', "toDate":'2022-12-20 13:15:00', "tool":"minical02"}  
# Run the Named Query.
table = system.db.runNamedQuery("MiniCal_FaultCodes", params)
value = system.dataset.toPyDataSet(table) #Don't need this: 
#for row in value:
#	print row[0], row[1], row[2], row[3], row[4]
stationList = value.getColumnAsList(4)
print type(value)
x=0
newData = []
if len(value) == 7:
	print [
	{	
		value[row]["station"]
	}	for row in range (0, len(value))]
else:
# Finding missing elements in List
	for row in range (0, 7):
		x +=1
		if x not in stationList: 
			value.append([0.0 0.0 0.0 0.0 x])

It's not taking the x as a variable ... :confused:

I don't really understand what you're trying to do as a whole, but the error you're getting is because you're trying to read a "value" attribute from an integer, which doesn't have this. Remove .value from that part. I think you'll then get an error that an int can't be used with len

You can't have spaces in a list. you have to comma-separate your values

Thanks, I am trying to append [0.0 0.0 0.0 0.0 x]
where x =6 in this case into my PyDataset

But after trying this line:

value.append([0.0, 0.0, 0.0, 0.0, x])

I get this:

Traceback (most recent call last):
  File "<input>", line 22, in <module>
AttributeError: 'com.inductiveautomation.ignition.common.script.bui' object has no attribute 'append'
>>> 

A PyDataSet has no append method. You need to use system.dataset.addRow
https://docs.inductiveautomation.com/display/DOC81/system.dataset.addRow

Also keep in mind that a dataset is immutable, so to change it, you need to reassign it
e.g.
value = system.dataset.addRow(value, ...)

1 Like

Thank you very much!