@EliHarold's answer is great. It is very concise. It uses list comprehensions, which I found to be confusing when I first start using Python. Even now, I often prefer to use an explicit for loop.
Here is one brute force method that you could use to first extract the third column, and then use the built-in min
function in Python to find the minimum of a 1D list. Python uses zero-based indexes, so if you want the third column, you need to use index 2.
data=[
[514.8,526.9,512,525,27942414],
[527.9,528.5,507.15,499,19353195],
[510,522.2,504.8,520.85,21799071],
[519.95,523.2,512,515.7,18364451],
[510.4,513.85,494.25,501.85,17946821],
]
col3 = []
for row in data:
col3.append(row[2])
minimum = min(col3)
print(minimum)
But even your original code will work if you use an alternate form of the range function*:
range(stop)
range(start, stop[, step])
If we use the second version of the syntax in the form of range(1, step)
, then we can use the first row to set a minval to compare to and range through second and following rows:
data=[
[514.8,526.9,512,525,27942414],
[527.9,528.5,507.15,499,19353195],
[510,522.2,504.8,520.85,21799071],
[519.95,523.2,512,515.7,18364451],
[510.4,513.85,494.25,501.85,17946821],
]
minval = data[0][2]
for i in range(1, len(data)):
if minval > data[i][2]:
minval = data[i][2]
print(minval)
* OK, strictly speaking range() isn't a function, but a type that is a immutable sequence of numbers.