Brazilian elections, a Jupyter Notebook and some data mining tools: the truths we don’t want to hear about a society that is inherently unequal.
By: Angelo Reale
Tags: Election 2018, Jupyter Notebook, Python, Data Mining, Brazil

(October, 7th. 2018.)

Original text:

Overview

Brazil, 2018. And yet, I won’t be here discussing about the World Cup and how Belgium managed to kick us out from being among the current top-tier national football teams in the world. As a matter of fact, I’m here to present you to rather alarming results obtained after a minor research conducted by me over the course of the past weeks.

This research was wrought up due to mainly two factors: 1) a reasonably inner desire to learn new Data Mining techniques, topic which I haven’t had the opportunity to delve further throughout my career and 2) to find out whether there could be some meaningful relationships between the declared wealth of all brazilian electoral candidates in 2018 and characteristics such as gender, ethnicity, affiliations, among others.

The research itself wasn’t thriving to be a fully-fledged, one-stop reference for all the relationships between these workable data. In fact, my lack of in-depth knowledge on statistics wouldn’t even allow me to come up with such a complete unveiling of that.

Consider it as a mere playful way of learning Python and Data Mining techniques in a real life situation with pragmatic, yet simple objectives.

The Data

A good — and handy — advancement, was that, in spite of all the mess we find here in Brazil, especially among the public sector institutions and in comparison with other developed countries, at least the TSE (Superior Electoral Tribunal), managed to keep tidily organized many publicly available databases with records of all the democratic elections since 1994. All files come in text format, with comma separated values, and a pretty comprehensive syntax for their headers (which helped a lot, since I was unable to find a table detailing what all of the columns were standing for).

This repository can be accessed and downloaded for free at: http://www.tse.jus.br/eleicoes/estatisticas/repositorio-de-dados-eleitorais-1/repositorio-de-dados-eleitorais

The Technology

— Ok, I have a loooooot of data. What’s next?

So I’ve googled for hands-on tutorials and references on Data Mining with Python. During this research I was able to quickly skim over the surface of technologies such as Jupyter (which acts as a real-time emulation environment for Python), Pandas (think of it as a library for reading/writing all sorts of structured data into arrays or files such as csv, txt, json, xml, etc.), Matplotlib (yet another library for plotting numbers into simple graphics), Numpy (the calculator library of Python), Scipy (the scientific calculator of Python) and Seaborn (an advanced — and pretty pretty — graphic plotter for Python).

Done. I had enough technologies for doing this research and could, thus begin the dirty work.

Among the programming tasks were:

1) Read from the two tables (one with the declared goods of the candidates and the other with the basic info about them).

2) Merge the two tables based on a common key.

3) Filter out all the dozens and dozens of irrelevant columns that had no purpose in this research.

4) Fix a slight currency issue (since Brazil writes currency decimals with commas instead of dots, making them to be read as strings, though I needed float numbers to calculate).

5) Sum all the declared goods into a single value per candidate.

6) Draw two simple histograms with matplotlib.

7) Generate basic statistics with Stats Models lib (since most of the relevant data was subjective and organized non-linearly with categories, these numerical statistics didn’t bear much relevancy to me).

8) Generate all sorts of graphic plots with Seaborn in order to visualize superficially what would be going on among several crossed relationships (wealth x gender, wealth x ethnicity, wealth x education, etc.)

Here is the full GitHub venv repository in case you’d like to check the code: https://github.com/angeloreale/tse-candidatesxgoods-script

The results

The results were, after all, very interesting to come across, and from a bunch of meaningless information, I could confirm a few rather unfortunate ones. I would thus, pinpoint at least four informations that made me spend some thought into them:

Female identified candidates (right column) own consistently less declared goods than male identified ones (left column).

2) White declared candidates (1st column) and mixed ethnicity (3rd column) own consistently more than black declared ones (2nd column).

3) Lower congress candidates (6th column) are, on occasion, more wealthy than other positions’ candidates.

4) Of all the political parties, there is one (called PROS) that is consistently more wealthy than the other ones, including one of it’s candidates, Edvaldo Brito, from São Paulo, the wealthiest among them all, with a fortune that surpasses 1.2 billion brazilian reais (equivalent to over 310 million US dollars).

Final Considerations

Curious, huh? All in all, politicians are a reflex of our society, so, this superficial research only serves to reiterate what already knew, or at least suspected.

I really hope that, in spite of all this mess Brazil is currently living, we can manage to generally evolve as a society, and, by doing so, help to undermine such levels of particular inequalities, shaping then, a more just land for our next generations to live in. There is no one but ourselves to blame, at least in a democracy (regime which is unimaginably jeopardized in Brazil at the present moment).

Every question we ask, every answer we give, every handshake and vow we make, will impair — or not — a difference in the future. So, as a friend and fellow brother says: full attention, constant observation, and unshaken perception.