Skip to content

Instantly share code, notes, and snippets.

@rickymoorhouse
Last active July 9, 2022 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickymoorhouse/ee25dcc299cddd5798e3edef48a3e65c to your computer and use it in GitHub Desktop.
Save rickymoorhouse/ee25dcc299cddd5798e3edef48a3e65c to your computer and use it in GitHub Desktop.
Parse SATs data from CSV to line per pupil
import csv
import logging
list = {}
filename = 'AllSubject_Result.csv'
"""
0 CurrLA
1 CurrESTAB
2 CurrDfENo
3 PrevDfENo
4 CurrURN
5 ToECode
6 Surname
7 Middlenames
8 Forename
9 DOB
10 Gender
11 CurrUPN
12 DCAReference
13 RecordSource
14 Subject
15 TestModification
16 TestStatus
17 TestMark1
18 TestMark1A
19 TestMark2
20 TestMark2A
21 TestMark3
22 TestMark3A
23 RawScore
24 TotalMarkA
25 ScaledScore
26 TestOutcome
27 Review
28 SpecialConsideration
29 CompensatoryMarks
30 RefTest
"""
with open(filename, newline='') as csvfile:
datareader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in datareader:
try:
fullname = row[8] + " " + row[6]
if fullname not in list:
list[fullname] = {"name": fullname}
list[fullname]["forename"] = row[8]
list[fullname]["surname"] = row[6]
list[fullname]["{}1".format(row[14])] = row[17]
list[fullname]["{}1a".format(row[14])] = row[18]
list[fullname]["{}2".format(row[14])] = row[19]
list[fullname]["{}2a".format(row[14])] = row[20]
list[fullname]["{}3".format(row[14])] = row[21]
list[fullname]["{}3a".format(row[14])] = row[22]
list[fullname]["{}raw".format(row[14])] = row[23]
list[fullname]["{}scaled".format(row[14])] = row[25]
except IndexError as indexException:
logging.exception(indexException)
print("Name\tSurname\tArithmetic\tReasoning 1\tReasoning 2\tRaw Score\tScaled Score\tReading\tRaw Score\tScaled Score\tEnglish 1\tEnglish 2\tRaw Score\tScaled Score")
for pupil in list:
try:
print("{forename}\t{surname}\t{M1}\t{M2}\t{M3}\t{Mraw}\t{Mscaled}\t{R3}\t{Rraw}\t{Rscaled}\t{G2}\t{G3}\t{Graw}\t{Gscaled}".format(**list[pupil]))
except KeyError as keyError:
logging.exception(keyError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment