I am trying to pull out all the relevant info for the lines with the minimum value in a csv file with Python. Below is my code to find out the relevant information. The minimum value is 12 when I code it spaerately. But when I put in the function and will process the minimum to find and record other data in the csv file.The value can not be updated. What I am missing to update the value of line[9]?
The CVS file contains a column of numbers and I need to find the minimum. The separate coding works well to find the minimum of 12 and I did it as a test. But it does not work after I assign a function and use the same method to find the minimum. As I need to use the minimum in other part of the code, it is better if I can put it in the function and make it work. So I would like to know how should transfer the function also works in finding the minimum. Thank you in advance.
#put finding minimum in to a function and will use the returned minimum
#to pull out other information
def findMin():
minMile = 100
if num<minMile:
minMile=num
return minMile
def main():
fileIn = open("epaVehicleData2008.csv", "r")
fileIn.readline()
for line in fileIn:
line = line.split(",")
num=int(line[9])
findmin(line)
minMile=int(line[9])
print(minMile)
main()
#separate code for finding the minimum as a test
fileIn = open("epaVehicleData2008.csv", "r")
fileIn.readline()
minMile = 100
for line in fileIn:
line = line.split(",")
num = int(line[9])
if num < minMile:
minMile = num
print(minMile)