Last active
July 9, 2022 09:04
-
-
Save rickymoorhouse/ee25dcc299cddd5798e3edef48a3e65c to your computer and use it in GitHub Desktop.
Parse SATs data from CSV to line per pupil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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