I'm reading data from csv file and trying to sort data by using particular column for example reading data to 100 students from csv file and have to sort data according to marks
import csv
import operator
with open('Student_Records.csv', 'r') as csvFile:
reader = csv.reader(csvFile)
for row in reader:
print(row)
sortedlist = sorted(reader, key=operator.itemgetter(7), reverse=True)
for eachline in sortedlist:
print(eachline)
csvFile.close()
csv file in excel sheet and that file doesn't have column names, following is the csv file data
1,Lois,Walker,F,[email protected],Donald Walker,Helen Walker,40,303-572-8492
2,Brenda,Robinson,F,[email protected],Raymond Robinson,Judy Robinson,80,225-945-4954
3,Joe,Robinson,M,[email protected],Scott Robinson,Stephanie Robinson,70,219-904-2161
4,Diane,Evans,F,[email protected],Jason Evans,Michelle Evans,90,215-793-6791
5,Benjamin,Russell,M,[email protected],Gregory Russell,Elizabeth Russell,56,262-404-2252
6,Patrick,Bailey,M,[email protected],Ralph Bailey,Laura Bailey,36,319-812-6957
7,Nancy,Baker,F,[email protected],Scott Baker,Judy Baker,78,229-336-5117
key=operator.itemgetter(7), you need to change your key. Post a part of your csv for further help?