My aim is to find the max of the individual column and print out the information. But there is problem when I print some of the information. For example CSIT135
, nothing was printed out. CSIT121
only prints out one result.
My data looks like:
first_name,last_name,student_id,CSIT110,CSIT121,CSIT135,CSIT142
Peter,Tan,S1012342D,89,67,54,78
John,Lim,S1014322H,87,78,86,67
Ada,Ang,S1023456I,54,78,65,54
def test():
import csv
with open("data.csv") as a:
rows = csv.DictReader(a)
t2_list=[]
for row in rows:
t2 = row['CSIT121']
t2_list.append(t2)
CSIT121=max(t2_list)
if row['CSIT121']==CSIT121:
print("{0:<8}| {1:>10} | {2:<8}".format("CSIT121", "John","Lim"))
print("{0:<8}| {1:>10} | {2:<8}".format("CSIT121", row['first_name'],row['last_name']))
with open("data.csv") as a:
rows = csv.DictReader(a)
t3_list=[]
for row in rows:
t3 = row['CSIT135']
t3_list.append(t3)
CSIT135=max(t3_list)
if row['CSIT135']==CSIT135:
print("{0:<8}| {1:>10} | {2:<8}".format("CSIT135", row['first_name'],row['last_name']))
Code sample and run result pic
See Question&Answers more detail:os