module data.elections#

Short summary#

module actuariat_python.data.elections

Various function to download data about French elections.

source on GitHub

Classes#

class

truncated documentation

_HTMLToText

Functions#

function

truncated documentation

_elections_vote_place_address_patterns_

elections_legislatives_bureau_vote

Retrieves data from Résultat des élections législatives françaises de 2012 au niveau bureau de vote. …

elections_legislatives_circonscription_geo

Retrieves data from Countours des circonscriptions des législatives. …

elections_presidentielles

Downloads the data for the French elections from data.gouv.fr.

elections_presidentielles_local_files

Returns the list of files included in this module about French elections.

elections_vote_place_address

Scrapes and extracts addresses for every vote place (bureau de vote in French).

elections_vote_places_geo

Retrieves data vote places (bureaux de vote in French) with geocodes.

html_to_text

Given a piece of HTML, return the plain text it contains. This handles entities and char refs, but not javascript and …

villes_geo

Retrieves data vote places (bureaux de vote in French) with geocodes.

Methods#

method

truncated documentation

__init__

get_text

handle_charref

handle_data

handle_endtag

handle_entityref

handle_startendtag

handle_starttag

Documentation#

Various function to download data about French elections.

source on GitHub

class actuariat_python.data.elections._HTMLToText#

Bases : HTMLParser

Initialize and reset this instance.

If convert_charrefs is True (the default), all character references are automatically converted to the corresponding Unicode characters.

__init__()#

Initialize and reset this instance.

If convert_charrefs is True (the default), all character references are automatically converted to the corresponding Unicode characters.

actuariat_python.data.elections._elections_vote_place_address_patterns_()#
actuariat_python.data.elections.elections_legislatives_bureau_vote(source=None, folder='.', fLOG=<function noLOG>)#

Retrieves data from Résultat des élections législatives françaises de 2012 au niveau bureau de vote.

Paramètres:
  • source – should be None unless you want to use the backup plan (« xd »)

  • folder – where to download

Renvoie:

list of dataframe

Others sources:

source on GitHub

actuariat_python.data.elections.elections_legislatives_circonscription_geo(source='xd', folder='.', fLOG=<function noLOG>)#

Retrieves data from Countours des circonscriptions des législatives.

Paramètres:
  • source – should be None unless you want to use the backup plan (« xd »)

  • folder – where to download

Renvoie:

list of dataframe

source on GitHub

actuariat_python.data.elections.elections_presidentielles(url=None, local=False, agg=None)#

Downloads the data for the French elections from data.gouv.fr.

Paramètres:
  • url – url (None for default value)

  • local – prefer local data instead of remote

  • agg – kind of aggregation desired (see below)

Renvoie:

dictionaries of DataFrame (one entry for each round)

The default url comes from Elections présidentielle 2012 - Résultats. You can get more at Elections présidentielles 1965-2012.

If url is None, we pull some data from folder data/election.

Parameter agg:

  • circ or None for no aggregation

  • dep to aggregate per department

source on GitHub

actuariat_python.data.elections.elections_presidentielles_local_files(load=False)#

Returns the list of files included in this module about French elections.

Paramètres:

load – True: load the data

Renvoie:

list of local files

If the data is loaded, the function returns a dictionary of dataframe, one per round.

source on GitHub

actuariat_python.data.elections.elections_vote_place_address(folder='.', hide_warning=False, fLOG=<function noLOG>)#

Scrapes and extracts addresses for every vote place (bureau de vote in French).

Paramètres:
  • folder – where to download the scraped pages

  • hide_warnings – hide warnings

  • fLOG – logging function

Renvoie:

dictionary

The function does not retrieve everything due to the irregular format. Sometimes, the city is missing or written above.

source on GitHub

actuariat_python.data.elections.elections_vote_places_geo(source='xd', folder='.', fLOG=<function noLOG>)#

Retrieves data vote places (bureaux de vote in French) with geocodes.

Paramètres:
  • source – should be None unless you want to use the backup plan (« xd »)

  • folder – where to download

  • fLOG – logging function

Renvoie:

list of dataframe

source on GitHub

actuariat_python.data.elections.html_to_text(html)#

Given a piece of HTML, return the plain text it contains. This handles entities and char refs, but not javascript and stylesheets.

source on GitHub

actuariat_python.data.elections.villes_geo(folder='.', as_df=False, fLOG=<function noLOG>)#

Retrieves data vote places (bureaux de vote in French) with geocodes.

Paramètres:
  • folder – where to download

  • as_df – return as a dataframe

  • fLOG – logging function

Renvoie:

list of dataframe

source on GitHub