I am trying to get the maximum value listed on a CSV file in one particular column. I cannot use pandas yet so everything has to be basic.
CSV sample data is:
grant 313 2014 grant 976 2013 grant 245 2012 grant 90 2011 grant 962 2010
Output needs to be: grant made 976 in 2013
--> which is the maximum value under the name
grant and the year was made.
My code is:
import csv
Empmax = input("Enter employee name: ")
maxMade = 0
with open("data.csv") as file:
reader = csv.reader(file)
for line in reader:
name = line[0]
year = line[1]
made = line[2]
if Empmax.lower() == name.lower():
if int(made) > maxMade:
maxMade = int(made)
print(Empmax, "made", maxMade, "in", int(year))
Output comes out like this: grant made 962 in 2010
.
Updated it and I got the max: I used: if int(made) > maxMade: from benny's example. Though year is still not updating.