Success!
I managed to solve this in the end both by including the write loop inside of the read loop, also by including the delimiter and fieldnames parameters along with the if statement to check for fieldnames being recognised as data.
Use of icecream for debugging was invaluable!
with open(sys.argv[1]) as before, open(sys.argv[2], "w") as after: reader = csv.DictReader( before, fieldnames=["name", "house"], delimiter="," ) writer = csv.DictWriter(after, fieldnames=["first", "last", "house"]) # This line writes the header row to the CSV file, based on the field names provided earlier writer.writeheader() for row in reader: # This 'if' statement checks for fieldnames being recognised as data if row == {"house": "house", "name": "name"}: continue last, first = row["name"].split(",") new_format = { "first": first.lstrip(), "last": last, "house": row["house"], } # This line writes the content of the new_format dictionary as a row in the after CSV file writer.writerow(new_format)