 # Find max value in python dataset

I have a python dataset from an inspection gage that I calculate the derivative. Now I want to find the min and max values.

1, 0.11
2, 0.13
3, 0.00
4, 0.51
5, 0.31
6, 0.05
7, -0.31
8, 0.01
(there are 10,000 x,y values)

I need to return the values (4, 0.51) for the max function and (7, -0.31) for the min function. I have been looking on the net for answers but I cannot get them to work.

Any ideas?

I wanted to note that I am not at a standstill here as I do have working code. I was just looking for a cleaner way to do it.

```pydata = system.dataset.toPyDataSet(data) maxXval = 0.0 maxYval = 0.0 minXval = 0.0 minYval = 0.0 for row in pydata: if row["height"] > maxYval: maxYval = row["height"] maxXval = row["distance"] if row["height"] < minYval: minYval = row["height"] minXval = row["distance"]```

Just some ideas…

You can get the min/max like this from the orginal dataset (before it is converted to a pyDataSet):

print min(event.source.parent.test.data)
print max(event.source.parent.test.data)

From there, there must be a way to get the index of each value (as you would get a list index), but didn’t see it right away. I’ll look at the pyarray docs later.

Or, could you just sort the data in the dataset and grab the first and last rows? I’m not sure where your data comes from, so maybe that isn’t possible.

Or, as you iterate through your data, you could build two lists and then grab the min max values and their indexes. Something like this:

``````a=((2,5),(4,8),(0,-3))

m=[[],[]]
for i in a:
m.append(i)
m.append(i)
print a[m.index(min(m))]
print a[m.index(max(m))]

``````