Created
April 3, 2024 09:06
-
-
Save cnorthwood/5cd0c719eaf85d48c43d3d5db30db699 to your computer and use it in GitHub Desktop.
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 sys | |
def ballot_type(row): | |
if row["AVDescription"] == "Postal" and row["AVType"].startswith("Permanent"): | |
return "Perm Postal" | |
elif row["AVDescription"] == "Postal" and row["AVType"].startswith("Temporary"): | |
return "Postal" | |
elif row["AVDescription"] == "Proxy" and row["AVType"].startswith("Permanent"): | |
return "Perm Proxy" | |
elif row["AVDescription"] == "Proxy" and row["AVType"].startswith("Temporary"): | |
return "Proxy" | |
elif row["AVDescription"] == "Postal/Proxy" and row["AVType"].startswith("Permanent"): | |
return "Perm Postal Proxy" | |
elif row["AVDescription"] == "Postal/Proxy" and row["AVType"].startswith("Temporary"): | |
return "Postal Proxy" | |
else: | |
raise Exception(f"Unrecognised {row["AVDescription"]} {row["AVType"]}") | |
with open(sys.argv[1], encoding="windows-1252") as tsvfile: | |
reader = csv.DictReader(tsvfile, dialect="excel-tab") | |
with open("Processed Absent Voters.csv", "w") as outputcsvfile: | |
writer = csv.DictWriter(outputcsvfile, fieldnames=["PollingDistrict", "ElectorNumber", "BallotType"]) | |
writer.writeheader() | |
for row in reader: | |
writer.writerow({"PollingDistrict": row["DistrictRef"], "ElectorNumber": row["ElectorNumber"].split("-")[1], "BallotType": ballot_type(row)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment