Utilizing the files I parsed, I created this visualization of results from an August 2022 NY state senate district 7 primary election using Tableau. I also created visualizations on Datawrapper for an August 2022 NY gubernatorial primary, an August 2022 NY Congressional district 3 primary, and an August 2022 NY state senate district 7 primary.
The Nassau County Board of Elections provides election data in the form of hard-to-read .asc files. This Python script converts them to CSV files.
Make sure to configure the asc_directory and csv_directory variables with relevant paths on your computer. Also, this parser requires the Python library pandas.
- Modify the first two variables to set up your paths.
ASC directoryis the directory on your computer where the plain text ASCII file is (this is one that is usually provided by the Nassau BOE).CSV directoryis the directory on your computer where the parsed results will be stored. Make sure to complete this path with a slash (/) at the end in order to allow the data to be saved in the right place. A folder namedElection resultswill be created in that directory. These can be the same directory if you would like.- Below is example code.
asc_directory = "/Users/username/Documents/"
csv_directory = "/Users/username/Documents/BOE Files/" # make sure there is a slash at the end- Modify the latter two variables to configure which code is going to run.
- Set
is_primarytoTrueif the plain text ASCII file contains results of ANY primary election; otherwise, set it toFalse. - I recommend always setting
superior_formattingtoTrueas it does not just take the results of the ASCII file and convert them to CSV. It also formats the results such that each candidate's results are on the same line for each precinct and displays the number of total votes in the election and percentages received by each candidate. This is especially helpful if one is creating maps. However, superior formatting currently does not currently work for general election data, and if any bugs occur, try turning it off; it may fix them. - Below is a continuation of above's example code curated for this step.
is_primary = True
superior_formatting = True-
Run the code on your IDE or in the Terminal. FYI, I used Python 3.11, but it may work for earlier versions too. Create an issue on this GitHub if you run into any errors.
-
If you are making a map, do not the
IDcriteria to differentiate the precincts. Use theDISTRICTcriteria—it is linked thePrecinct namefield in the CSV file. Do not use thePrecinct codefield for this purpose (or do, I just can't figure how to use it with the maps I have).