About

Inspired by DecideChile, SERVEL, and Wikipedia, this project aims to develop an interactive visualization of Chilean parliamentary elections for both chambers of Congress using Python, QGIS, Highcharts, and integrating several public sources. Created by Sebastián RIFFO as an open-source product, its codes, data, and shapefiles produced are available in this github repository.

Visualization

For every election, information is portrayed at three different levels:

Individual results

Each icon represents the number of seats in the respective electoral division. If available, the detailed results are displayed, being possible to sort and filter them according to the elected members.

Results by electoral divisions

When interacting with an electoral district or senatorial constituency, the local results obtained by the main alliances are depicted. Otherwise, these are replaced by their overall votes.

Seat distribution

The composition of a chamber is presented in a apportionment diagram, with seats color-coded by alliances. These are further grouped by parties, each containing a list of their elected legislators.

The project

In the beginning, I just wanted to practice Python and challenge myself with something interesting, but instead of jumping into a competition, I decided to start my own project from scratch and see where it would lead me. Working on election data visualizations seemed suitable at the time, as I was committed to learning about apportionment methods. Soon enough, I realized I would need a large toolkit for developing what I had in mind, which is described below.

Web scraping, data cleansing and formatting was carried out using Beautiful Soup and Pandas, both well-known Python libraries. The visualization part, which prioritizes interacting with constituencies rather than just data, was built on Folium. For a newcomer like me, this library allows you to draw maps quickly, however its functionalities are quite rigid. A bit of JavaScript was necessary to tweak some, as well as HTML5/CSS to personalize certain elements. Since voting results are displayed on a table, TableSorter (Mottie’s fork) came in handy. Highcharts was really helpful to construct an apportionment diagram and provide a broader view of an election.

If electoral data is accessible since the so-called transition to democracy, vector maps are typically up-to-date, being this the main issue when dealing with old constituencies’ shapes. Hopefully, city boundaries have remained almost unchanged over the last 34 years, serving as a base to construct all election districts from 1989 onwards, with the help of Shapely.

Once finished, it made sense to extend the project to cover elections before 1989. I opted for the 1932-1973 period to bring some continuity, but also because electoral divisions slightly varied on those years. I used pyQGIS to georeference their boundaries, which was necessary due to the abrupt changes made to the country’s divisions by the later civilian-military dictatorship, making it impossible to recreate them using the current city boundaries. As for voting results, candidates’ information is no longer available, so I relied on the composition of each congressional term (La Nación, governmental newspaper back then, played a crucial role in verifying party affiliation). Eventually, I succeeded in reconstructing and balancing parties’ results for some elections, drawing from multiple sources.

Kwown issues

Ongoing developments

Future work