I have looked at this reference so please do not refer me to it.
Find max number in .CSV file in Python I struggled to modify this code to my own document for over
The max
function should handle that for you. In my below code I've already "read" the CSV (with fake data, but you seem to have a grasp on that portion)
data = [
["California", 123456],
["Idaho", 123],
["Utah", 2]
]
print max(data, key=lambda _: _[1])
This yields ['California', 123456]
The key=lambda _: _[1]
tells the function to use the second value of each record, the population in this case, to check the maximum.
Putting it all together should be something like:
def largestState():
INPUT = "statepopulations.csv"
COLUMN = 5
with open(INPUT, "rU") as csvFile:
data = csv.reader(csvFile)
next(data, None)
return max(data, key=lambda _: _[COLUMN])