In [110]:
import pandas as pd
import numpy as np

In [2]:
positions_c = ['legislature', 'identifiant', 'groupe', 'membres', 'pour', 'contre', 'nonvotants', 'abstention']
votes_c = ['legislature', 'identifiant', 'nom', 'prenom', 'groupe', 'position']

In [18]:
groupes = {
    u'Groupe socialiste, r\xe9publicain et citoyen': u'PS',
    u'Groupe Les R\xe9publicains': u'LR',
    u"Groupe de l'union des d\xe9mocrates et ind\xe9pendants": u'UDI',
    u'Groupe \xe9cologiste': u'Verts',
    u'Groupe radical, r\xe9publicain, d\xe9mocrate et progressiste': u'PRG',
    u'Groupe de la gauche d\xe9mocrate et r\xe9publicaine': u'FdG',
    u'Non inscrits': u'NI',
    u"Groupe de l'union pour un mouvement populaire": u'LR',
    u'Groupe rassemblement-union pour un mouvement populaire': u'UMP-Fillon',
}

In [19]:
pd.set_option('display.max_columns', None)

In [20]:
positions = pd.read_csv('output\\position.csv', sep=';', encoding='cp1252').reindex(columns=positions_c)

In [21]:
positions['groupe'] = positions.groupe.map(groupes)

In [23]:
from functools import reduce

In [24]:
positions['nb_null'] = \
    reduce(pd.Series.__add__, [positions[c].isnull().astype(int) for c in ['abstention', 'pour', 'contre', 'nonvotants']])

In [25]:
positions = positions.sort_values(['legislature', 'identifiant', 'groupe', 'nb_null'])\
                     .drop_duplicates(subset=['legislature', 'identifiant', 'groupe'], keep='first')\
                     .reindex(columns=positions_c)

In [27]:
positions.set_index(['legislature', 'identifiant', 'groupe']).unstack().swaplevel(0, 1, axis=1).sortlevel(axis=1).fillna(0)


Out[27]:
groupe FdG LR NI PRG PS UDI UMP-Fillon Verts
membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention membres pour contre nonvotants abstention
legislature identifiant
14 1 15 3 0 0 12 196 0 194 2 0 10 1 6 2 1 15 14 0 1 0 294 267 0 27 0 29 0 25 0 4 0 0 0 0 0 18 17 0 1 0
2 15 2 0 0 0 196 0 41 0 0 8 1 0 0 1 16 1 0 1 0 295 57 0 25 0 29 0 7 0 0 0 0 0 0 0 18 0 0 1 0
3 15 0 3 0 0 196 74 2 0 0 8 2 0 0 1 16 0 2 1 0 295 0 161 24 0 29 5 0 0 0 0 0 0 0 0 18 0 10 1 0
4 15 0 3 0 0 196 78 0 1 0 8 2 0 0 0 16 0 1 1 0 295 0 166 24 0 29 8 0 0 0 0 0 0 0 0 18 0 7 1 0
5 15 2 0 0 0 196 0 52 0 0 8 0 0 0 0 16 0 0 1 0 295 82 8 24 0 29 0 4 0 0 0 0 0 0 0 18 5 0 1 0
6 15 0 3 0 0 196 22 0 0 0 8 0 0 0 0 16 0 0 1 0 295 0 87 25 0 29 2 0 0 0 0 0 0 0 0 18 0 0 1 0
7 15 2 0 0 0 196 0 16 1 0 8 0 0 0 3 16 0 0 1 0 295 41 0 24 0 29 0 0 0 0 0 0 0 0 0 18 1 1 1 0
8 15 2 0 0 0 196 6 26 0 0 8 1 1 0 0 16 0 0 1 0 295 6 92 25 5 29 10 0 0 0 0 0 0 0 0 18 4 0 1 0
9 15 0 0 0 2 196 6 22 0 0 8 2 0 0 0 16 0 0 1 0 295 6 86 25 7 29 10 0 0 0 0 0 0 0 0 18 0 0 1 4
10 15 3 0 0 0 196 0 34 0 0 8 0 2 0 0 16 0 0 1 0 295 99 4 25 0 29 0 12 0 0 0 0 0 0 0 18 4 0 1 0
11 15 2 0 0 0 196 0 32 0 0 8 0 0 0 0 16 0 0 1 0 295 93 2 25 0 29 0 6 0 0 0 0 0 0 0 18 4 0 1 0
12 15 2 0 0 0 196 0 21 0 0 8 0 0 0 0 16 0 0 1 0 295 87 0 25 0 29 2 2 0 0 0 0 0 0 0 18 0 0 1 0
13 15 0 2 0 0 196 0 18 0 1 8 0 0 0 0 16 0 0 1 0 295 1 87 25 0 29 4 0 0 0 0 0 0 0 0 18 0 0 1 0
14 15 0 3 0 0 196 31 0 0 0 17 1 2 0 0 16 0 3 0 0 287 0 116 2 0 29 6 1 0 0 0 0 0 0 0 17 0 2 0 0
15 15 0 3 0 0 196 33 0 0 0 17 1 2 0 0 16 0 3 0 0 287 0 119 2 0 29 7 0 0 0 0 0 0 0 0 17 0 2 0 0
16 15 0 4 0 0 196 14 0 0 0 7 0 0 0 0 16 0 1 0 0 297 0 105 1 0 29 5 0 0 0 0 0 0 0 0 17 0 4 0 0
17 15 4 0 0 0 196 14 0 0 0 7 0 0 0 0 16 0 0 0 0 297 79 2 1 0 29 4 0 0 0 0 0 0 0 0 17 0 0 0 0
18 15 2 0 0 0 195 0 30 0 2 7 0 2 0 0 16 1 0 0 0 297 92 0 1 1 30 0 5 0 0 0 0 0 0 0 17 11 0 0 0
19 15 0 2 0 0 195 28 0 0 0 7 2 0 0 1 16 1 0 0 0 297 0 144 2 4 30 3 0 0 0 0 0 0 0 0 17 0 7 0 0
20 15 2 0 0 0 195 0 27 0 0 7 0 3 0 0 16 2 0 0 0 297 144 2 2 0 30 0 4 0 0 0 0 0 0 0 17 8 0 0 0
21 15 0 0 0 2 195 14 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 39 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
22 15 0 0 0 0 195 12 0 0 0 7 0 0 0 0 16 0 1 0 0 297 0 39 2 0 30 2 0 0 0 0 0 0 0 0 17 0 2 0 0
23 15 0 0 0 0 195 12 0 0 0 7 0 0 0 0 16 0 1 0 0 297 0 33 2 0 30 2 0 0 0 0 0 0 0 0 17 0 2 0 0
24 15 0 2 0 0 195 8 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 44 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
25 15 0 2 0 0 195 8 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 44 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
26 15 0 2 0 0 195 8 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 44 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
27 15 0 2 0 0 195 8 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 44 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
28 15 0 2 0 0 195 6 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 42 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
29 15 0 2 0 0 195 8 0 0 0 7 0 0 0 0 16 0 0 0 0 297 0 42 2 0 30 0 0 0 0 0 0 0 0 0 17 0 2 0 0
30 15 1 13 0 1 195 167 17 0 6 7 0 7 0 0 16 14 0 0 2 297 264 20 1 9 30 28 1 0 1 0 0 0 0 0 17 3 12 0 2
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1181 15 0 1 0 0 199 14 0 1 0 10 0 1 0 0 18 1 0 0 0 287 22 9 1 0 30 1 0 0 0 0 0 0 0 0 18 0 1 0 1
1182 15 0 0 0 0 199 15 0 1 0 10 0 0 0 0 18 1 1 0 0 287 0 23 1 0 30 1 0 0 0 0 0 0 0 0 18 0 0 0 0
1183 15 0 0 0 0 199 20 0 0 0 10 0 0 0 0 18 0 1 0 0 287 18 3 1 2 30 1 0 0 0 0 0 0 0 0 18 0 0 0 0
1184 15 0 0 0 0 199 10 0 0 0 10 0 0 0 0 18 0 0 0 0 287 1 22 2 0 30 0 0 0 0 0 0 0 0 0 18 0 0 0 0
1185 15 2 12 0 1 199 0 196 0 0 10 1 6 0 0 18 10 0 0 2 287 264 1 1 18 30 0 27 0 0 0 0 0 0 0 18 9 3 0 6
1186 15 0 0 0 0 199 3 0 1 0 10 0 0 0 0 18 0 1 0 0 287 0 13 1 3 30 1 0 0 0 0 0 0 0 0 18 1 0 0 0
1187 15 0 0 0 0 199 6 1 0 3 10 0 0 0 0 18 3 0 0 0 287 41 0 2 0 30 0 0 0 2 0 0 0 0 0 18 3 0 0 0
1188 15 0 0 0 0 199 0 10 0 0 10 0 0 0 0 18 1 1 0 0 287 31 7 2 3 30 0 3 0 0 0 0 0 0 0 18 3 0 0 0
1189 15 2 12 0 1 199 0 196 0 0 10 2 8 0 0 18 15 0 0 3 287 262 1 1 15 30 0 27 0 2 0 0 0 0 0 18 9 0 0 9
1190 15 0 6 0 0 199 101 1 0 0 10 4 3 0 0 18 5 1 0 0 287 2 173 1 0 30 16 0 0 0 0 0 0 0 0 18 0 14 0 0
1191 15 15 0 0 0 199 194 0 0 0 10 9 0 0 0 18 18 0 0 0 287 271 3 1 1 30 29 0 0 0 0 0 0 0 0 18 15 3 0 0
1192 15 1 0 0 0 199 0 42 0 0 10 1 1 0 0 18 0 7 0 0 287 28 45 1 2 30 1 4 0 0 0 0 0 0 0 18 1 3 0 1
1193 15 0 0 0 0 199 0 42 1 0 10 1 1 0 0 18 0 7 0 0 287 10 54 1 5 30 0 5 0 0 0 0 0 0 0 18 0 4 0 1
1194 15 0 1 0 0 199 42 0 1 0 10 1 1 0 0 18 7 0 0 0 287 44 25 1 4 30 4 1 0 0 0 0 0 0 0 18 4 1 0 0
1195 15 1 0 0 10 199 176 1 0 0 10 7 0 0 0 18 18 0 0 0 287 269 2 1 0 30 30 0 0 0 0 0 0 0 0 18 14 1 0 0
1196 15 0 0 0 0 199 30 0 0 0 10 0 0 0 0 18 2 0 0 0 287 17 50 2 4 30 5 0 0 0 0 0 0 0 0 18 0 6 0 0
1197 15 0 0 0 1 199 0 27 0 0 10 0 0 0 0 18 0 1 0 0 287 50 6 2 2 30 0 5 0 0 0 0 0 0 0 18 4 0 0 0
1198 15 0 0 0 0 199 0 6 0 0 10 0 0 0 0 18 1 0 0 0 287 20 1 1 0 30 1 15 0 0 0 0 0 0 0 18 1 0 1 0
1199 15 0 0 0 0 199 4 0 0 0 10 0 0 0 0 18 0 0 0 0 287 4 8 2 1 30 1 0 0 0 0 0 0 0 0 18 0 0 0 0
1200 15 1 11 0 2 199 0 199 0 0 10 3 5 0 0 18 11 1 0 6 287 264 1 2 7 30 0 26 0 0 0 0 0 0 0 18 17 0 0 1
1201 15 0 0 0 0 199 0 11 0 0 10 0 0 0 0 18 0 0 0 0 287 26 0 2 1 30 0 1 0 0 0 0 0 0 0 18 0 0 0 0
1202 15 2 12 0 0 199 0 198 0 0 11 1 7 0 0 18 16 2 0 0 287 269 0 2 11 29 0 26 0 2 0 0 0 0 0 18 8 1 0 6
1203 15 0 0 0 0 199 0 0 0 1 11 0 0 0 0 18 1 0 0 0 287 14 4 1 3 29 0 0 0 0 0 0 0 0 0 18 0 3 0 0
1204 15 0 0 0 0 199 0 6 0 0 11 0 0 0 0 18 1 1 0 0 287 8 14 2 0 29 0 0 0 0 0 0 0 0 0 18 2 0 0 0
1205 15 0 0 0 0 199 0 10 0 0 11 1 0 0 0 18 0 0 0 0 287 15 29 2 1 29 0 1 0 0 0 0 0 0 0 18 6 0 0 0
1206 15 0 0 0 0 199 1 5 0 0 11 1 0 0 0 18 0 0 0 0 287 19 18 2 0 29 0 1 0 0 0 0 0 0 0 18 7 0 0 0
1207 15 0 0 0 0 199 4 0 0 0 11 0 1 0 0 18 0 0 0 0 287 20 13 2 0 29 1 0 0 0 0 0 0 0 0 18 0 7 0 0
1208 15 1 0 0 0 199 0 0 1 5 11 1 0 0 0 18 0 1 0 0 287 1 20 1 1 29 1 0 0 0 0 0 0 0 0 18 1 1 0 1
1209 15 0 0 0 0 199 2 0 1 0 11 1 0 0 0 18 0 1 0 0 287 1 18 1 0 29 1 0 0 0 0 0 0 0 0 18 0 1 0 1
1210 15 1 0 0 0 199 5 0 1 0 11 1 0 0 0 18 0 1 0 0 287 1 18 1 0 29 1 0 0 0 0 0 0 0 0 18 2 0 0 0

1210 rows × 40 columns


In [28]:
deputes = pd.read_csv('output/depute.csv', sep=';', encoding='cp1252')

In [31]:
deputes['nom'] = deputes.nom.map(lambda s: ' '.join(s.split(' ')[1:]))

In [86]:
votes = pd.read_csv('output/vote.csv', sep=';', encoding='cp1252').reindex(columns=votes_c)

In [87]:
votes['groupe'] = votes['groupe'].map(groupes)
votes['position'] = votes['position'].astype('category', categories=['pour', 'contre', 'non-votant', 'abstention', 'absent'])

In [130]:
import unicodedata
def strip_accents(s):
   return ''.join(c for c in unicodedata.normalize('NFD', s)
                  if unicodedata.category(c) != 'Mn')

In [150]:
noms = votes[['nom', 'prenom']].drop_duplicates().sort_values(['nom', 'prenom'])

In [151]:
noms_votes = noms['prenom'] + ' ' + noms['nom']

In [152]:
tr = str.maketrans('\xa0-', ' '*2)

In [162]:
transformations = {
    'Genevieve Gosselin': 'Genevieve Gosselin Fleury',
    'Gerard MENUEL': 'Gerard Menuel',
}

In [163]:
noms_votes = set((noms['prenom'] + ' ' + noms['nom']).map(strip_accents).replace(transformations).str.translate(tr))

In [164]:
noms_deputes = set(deputes['nom'].map(strip_accents).str.translate(tr))

In [165]:
noms_votes - noms_deputes


Out[165]:
{'Claude Bartolone'}

In [169]:
votes['nom complet'] = (votes['prenom'] + ' ' + votes['nom']).map(strip_accents).replace(transformations).str.translate(tr)

In [171]:
tableau = votes.reindex(columns=['nom complet', 'identifiant', 'position'])\
               .set_index(['identifiant', 'nom complet'])['position']\
               .unstack().fillna('absent')

In [172]:
tableau.to_csv('output/tableau.csv', sep=';', encoding='cp1252')