I’m trying to sum the first 12 rows of a dataset. Currently I have a total of all the rows.
pds=system.dataset.toPyDataSet(data)
total = 0
for row in pds:
total += row[2]
print (total)
How do I only sum the first 12 (assuming there are more than 12)?
Might be an even easier route, but could use a while loop instead of a for loop. That will let you specify the number of iterations versus using the full row quantity.
https://www.w3schools.com/python/python_while_loops.asp
Yeah, I’m not sure how to apply a count while iterating though the “rows in pds:”
jpark
June 7, 2019, 7:54pm
4
total = sum([row[2] for row in pds[:12]])
6 Likes
Ahh, I was trying to add the limit to row. Awesome thanks