So I have a function that finds the maximum value in a column in a csv file. I want to print the value thats on the same row as the max value, but in column 13. The code makes it clearer:
def bigQuake(inputfilename):
file = open(inputfilename,"r")
maxvalue = 0.0
for line in file:
value = line.split()
try:
p = float(line.split(",")[4])
maxvalue = max(maxvalue,p)
except:
pass
return maxvalue
The code above simply finds the maxvalue of column 4, what's not working is when I replace
return maxvalue
with
print("The largest earthquake was a " + maxvalue + "magnitude earthquake" + value[12])
value[12] is trying to find the value in column 12 that corresponds to the max value of column 4. Note that column 12 contains strings, so I want the output to look like this:
>>>bigQuake(file.csv)
>>>The largest earthquake was a 50 magnitude earthquake 10km from San Francisco.