In [1]:
import pandas as pd

In [2]:
def parseLinkField(fieldcont):
    fc = fieldcont.split(" ")
    id = fc[1].replace('"','')
    return {'Type de contenu':fc[0], 'Link':id}

In [3]:
location = "data/2015-11-30_projet-de-loi-numerique_consultation.anon.csv"
df = pd.read_csv(location)

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

In [5]:
df.columns.values


Out[5]:
array(['Identifiant', 'Auteur', "Id de l'auteur", 'Type de profil',
       'Cr\xc3\xa9ation', 'Modification', 'Titre', 'Type de contenu',
       'Cat\xc3\xa9gorie', 'Li\xc3\xa9 \xc3\xa0 :', 'Contenu', 'Lien',
       'Score', 'Total des votes', 'Votes pour', 'Votes mitig\xc3\xa9s',
       'Votes contre', 'Sources', 'Total des arguments', 'Arguments pour',
       'Arguments contre', 'Real identifiant',
       "Id anonymise de l'Auteur md5", "Id anonymise de l'Auteur int"], dtype=object)

In [6]:
df.head(5)


Out[6]:
Identifiant Auteur Id de l'auteur Type de profil Création Modification Titre Type de contenu Catégorie Lié à : Contenu Lien Score Total des votes Votes pour Votes mitigés Votes contre Sources Total des arguments Arguments pour Arguments contre Real identifiant Id anonymise de l'Auteur md5 Id anonymise de l'Auteur int
0 779 Michel LEBON 118 Citoyen 2015-10-18 23:25:02 2015-10-18 23:54:24 Accompagner d'une régulation adaptée l'object... Proposition TITRE III - Chapitre Ier - Section 1 n/a "Art 23 quater\n\n\nCet article engage l'ARCEP... n/a 1 1 1 0 0 0 1 1 0 Proposition "779" c2978e56db5048ed367624d9e78a5091 3264712278
1 782 Patricia Ahanda 10522 Citoyen 2015-10-18 23:54:00 NaN Mise en place d'un guide de l'élu en charge du... Proposition TITRE III - Chapitre Ier - Section 1 n/a "La probl\u00e9matique du num\u00e9rique est i... n/a 1 1 1 0 0 0 0 0 0 Proposition "782" cab6a5eff98dd29e399209300332ed5b 3400967663
2 781 Jérôme B. 12312 Citoyen 2015-10-18 23:33:09 NaN Créer un "Web français certifié" Proposition TITRE Ier - Chapitre Ier - Section 2 n/a "Donner corps \u00e0 l'\u00e9tat num\u00e9riqu... n/a 1 1 1 0 0 0 0 0 0 Proposition "781" 8f454b28b7fec5b96bb60990b71e29a0 2403683112
3 780 QUEGUINER CHARLES 30458 Citoyen 2015-10-18 23:25:07 NaN contre : le délai d'embargo sur les publicatio... Proposition TITRE Ier - Chapitre II - Section 2 n/a "Le conseil de laboratoire de l'Irisa soutien ... n/a 0 0 0 0 0 0 0 0 0 Proposition "780" b0b89231cc8b63c29e0ac29a8c0c215c 2964886065
4 778 Patricia Ahanda 10522 Citoyen 2015-10-18 22:48:42 NaN Une cartographie en temps réel du développemen... Proposition TITRE Ier - Chapitre Ier - Section 1 n/a "La question du d\u00e9ploiement de la fibre o... n/a 1 1 1 0 0 0 0 0 0 Proposition "778" cab6a5eff98dd29e399209300332ed5b 3400967663

In [7]:
contenus = df.groupby('Type de contenu')

In [8]:
contenus.count()


Out[8]:
Identifiant Auteur Id de l'auteur Type de profil Création Modification Titre Catégorie Lié à : Contenu Lien Score Total des votes Votes pour Votes mitigés Votes contre Sources Total des arguments Arguments pour Arguments contre Real identifiant Id anonymise de l'Auteur md5 Id anonymise de l'Auteur int
Type de contenu
Argument 5990 1890 1890 5990 5990 480 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990 5990
Modification 1387 491 491 1387 1387 216 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387 1387
Proposition 692 692 692 692 692 135 692 692 692 692 692 692 692 692 692 692 692 692 692 692 692 692 692
Source 415 273 273 415 415 43 415 415 415 415 415 415 415 415 415 415 415 415 415 415 415 415 415
Vote 147637 16972 16972 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637 147637

Votes analysis


In [9]:
votes_only = df[df['Type de contenu'] == 'Vote']

In [10]:
votes = votes_only[["Id anonymise de l'Auteur md5",'Catégorie','Li\xc3\xa9 \xc3\xa0 :']]

In [11]:
def getType(a):
    return parseLinkField(a)['Type de contenu']
def getIdCont(a):
    return parseLinkField(a)['Link']

In [14]:
votes['Type de contenu']=votes['Li\xc3\xa9 \xc3\xa0 :'].map(getType)

In [15]:
votes['Id Content']=votes['Li\xc3\xa9 \xc3\xa0 :'].map(getIdCont)

In [16]:
votes.head(5)


Out[16]:
Id anonymise de l'Auteur md5 Catégorie Lié à : Type de contenu Id Content
692 ace27604697eb998a4b9177584fba8ae Mitigé Proposition "79" Proposition 79
693 e43ff226a1a03efb0682c655581808e9 Mitigé Proposition "73" Proposition 73
694 4867b6518cea7f0cd4fbe823dcbcddee Mitigé Proposition "68" Proposition 68
695 f2ec0c3c46b8814f0c531a4838271f08 Mitigé Proposition "79" Proposition 79
696 7191b5f27b6773e60813616e6838fcf9 Mitigé Proposition "73" Proposition 73

Users


In [17]:
users = df.drop_duplicates(subset="Id anonymise de l'Auteur md5")["Id anonymise de l'Auteur md5"].to_frame()

In [18]:
users.sort("Id anonymise de l'Auteur md5").head(5)


Out[18]:
Id anonymise de l'Auteur md5
85625 000069ff1aaeb7e3ccc6be0399cd5dc5
34416 00011f405236a9bf64846a25e592e3f6
51930 0007e78f1f444f94481843e92c9d7ca3
71750 0008851ceb1d1c426402df926b8c974b
97358 0009543797e17cb64634ef66b42ff163

In [19]:
type(users)


Out[19]:
pandas.core.frame.DataFrame

Content


In [20]:
content = df[(df['Total des votes']!='0') & (df['Total des votes']!='n/a')]

In [21]:
content.groupby('Type de contenu').count()


Out[21]:
Identifiant Auteur Id de l'auteur Type de profil Création Modification Titre Catégorie Lié à : Contenu Lien Score Total des votes Votes pour Votes mitigés Votes contre Sources Total des arguments Arguments pour Arguments contre Real identifiant Id anonymise de l'Auteur md5 Id anonymise de l'Auteur int
Type de contenu
Argument 4147 1339 1339 4147 4147 347 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147 4147
Modification 1293 466 466 1293 1293 199 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293 1293
Proposition 684 684 684 684 684 135 684 684 684 684 684 684 684 684 684 684 684 684 684 684 684 684 684
Source 185 119 119 185 185 17 185 185 185 185 185 185 185 185 185 185 185 185 185 185 185 185 185

In [21]:


In [22]:
content.groupby("Id de l'auteur").count()


Out[22]:
Identifiant Auteur Type de profil Création Modification Titre Type de contenu Catégorie Lié à : Contenu Lien Score Total des votes Votes pour Votes mitigés Votes contre Sources Total des arguments Arguments pour Arguments contre Real identifiant Id anonymise de l'Auteur md5 Id anonymise de l'Auteur int
Id de l'auteur
12 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
16 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
57 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
97 7 7 7 7 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
106 5 5 5 5 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
112 6 6 6 6 2 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
114 31 31 31 31 0 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31
118 7 7 7 7 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
119 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
125 11 11 11 11 0 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
127 9 9 9 9 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
145 9 9 9 9 2 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
149 4 4 4 4 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
156 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
157 11 11 11 11 1 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
164 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
181 4 4 4 4 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
186 10 10 10 10 2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
188 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
195 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
199 5 5 5 5 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
204 39 39 39 39 8 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39
229 3 3 3 3 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
235 4 4 4 4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
254 15 15 15 15 1 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
257 12 12 12 12 0 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
263 13 13 13 13 2 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13
266 11 11 11 11 0 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
276 4 4 4 4 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
288 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
26719 7 7 7 7 0 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
27352 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
27379 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
27631 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
27767 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
27817 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
27830 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28322 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28376 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28567 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28642 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28762 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
28779 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
28855 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
28902 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
29017 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
29077 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29346 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29388 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
29399 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
29568 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
29666 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29682 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29704 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29772 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
29790 4 4 4 4 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
29956 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
30024 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
30183 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
30356 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

598 rows × 23 columns


In [22]:


In [22]:

Tangui's stuff


In [23]:
import sys
import pandas as pd

consultation1 = pd.read_csv("data/2015-11-30_projet-de-loi-numerique_consultation.anon.csv", encoding='utf-8')
consultation1.columns = [u'Identifiant', u'Auteur', u"Id de l'auteur", u'Type de profil', u'Création', u'Modification', u'Titre', u'Type de contenu', u'Catégorie', u'Lié à :', u'Contenu', u'Lien', u'Score', u'Total des votes', u'Votes pour', u'Votes mitigés', u'Votes contre', u'Sources', u'Total des arguments', u'Arguments pour', u'Arguments contre', u'Real identifiant', u"Id anonymise de l'Auteur md5", u"Id anonymise de l'Auteur int"]
consultation1.index = consultation1["Real identifiant"]
consultation1 = consultation1[consultation1["Type de contenu"] != "Vote"]
consultation2 = pd.read_csv("data/2015-11-30_projet-de-loi-numerique_consultation.anon.csv", encoding='utf-8')
consultation2.columns = [u'Identifiant 2', u'Votant', u"Id du votant", u'Type de profil votant', u'Création vote', u'Modification vote', u'Titre 2', u'Type de contenu 2', u'Catégorie 2', u'lien Real identifiant', u'Contenu 2', u'Lien 2', u'Score 2', u'Total des votes 2', u'Votes pour 2', u'Votes mitigés 2', u'Votes contre 2', u'Sources 2', u'Total des arguments 2', u'Arguments pour 2', u'Arguments contre 2', u'Real identifiant 2', u"Id anonymise du votant md5", u"Id anonymise du votant int"]
consultation2.index = consultation2["lien Real identifiant"]
consultation2 = consultation2[consultation2["Type de contenu 2"] == "Vote"]
consultation2 = consultation2[consultation2[u"Catégorie 2"] == "Pour"]
voter2contrib = consultation1.join(consultation2)[["Id anonymise de l'Auteur md5", "Id anonymise du votant md5", "Real identifiant"]]
voter2contribvote = voter2contrib.groupby(["Id anonymise de l'Auteur md5",'Id anonymise du votant md5']).count().reset_index()

In [24]:
voter2contrib.head(3)


Out[24]:
Id anonymise de l'Auteur md5 Id anonymise du votant md5 Real identifiant
Argument "10" dabb33d33b0c2215d32b5115ab670770 9bd7fb94576ddc568e19d05a097885a7 Argument "10"
Argument "10" dabb33d33b0c2215d32b5115ab670770 0f99b5c41530d5ffa1670c4023b99247 Argument "10"
Argument "10" dabb33d33b0c2215d32b5115ab670770 ab9ecaf95088188b76b006cdc8a3f761 Argument "10"

In [25]:
type(voter2contribvote)


Out[25]:
pandas.core.frame.DataFrame

In [26]:
voter2contribvote.reset_index()


Out[26]:
index Id anonymise de l'Auteur md5 Id anonymise du votant md5 Real identifiant
0 0 000cee58078f74fa00df929d5bde013b 5347327ea3c849437ea6198bdec59020 1
1 1 002ac77670effaab2d305426ae7580c8 6f721b03320332e5ec5197c4a78468fb 1
2 2 002ac77670effaab2d305426ae7580c8 7d35d935e2f950995d33e387ce564929 1
3 3 002ac77670effaab2d305426ae7580c8 dbe7c091e745536c1e153c7bf9ce9060 1
4 4 002ac77670effaab2d305426ae7580c8 e45e802c45c6e150bca4644d38ddebd6 1
5 5 002ac77670effaab2d305426ae7580c8 e6a4327efdd43dd3f5e43129e9ae62eb 1
6 6 002dac6af290451f7a7f7366f00b6050 569da28aa13a257839271c4214fa0253 1
7 7 002dac6af290451f7a7f7366f00b6050 b8141c15cd95232cff8a5945e8eeb4fe 1
8 8 005beaf1d8990b6057dd96dcedab046b 009cdc658da01828d21df27f296e4972 1
9 9 005beaf1d8990b6057dd96dcedab046b 55b94b9c27c79532de79e3cd2d48d6b5 1
10 10 005beaf1d8990b6057dd96dcedab046b 592cd1e45c6709928c6e7e27671932de 1
11 11 005beaf1d8990b6057dd96dcedab046b 78ce3688042e05d2e2bf8fa2ffcce621 1
12 12 005beaf1d8990b6057dd96dcedab046b bcb2c528a34f2f4722d8b81f26e39398 1
13 13 005beaf1d8990b6057dd96dcedab046b d925a08446e3808214ac54613768b4e5 1
14 14 0062d48e47ac8110d3ce5536a1c7be66 25ae9009dd7739d93a951828301cd49e 1
15 15 008291b4409b5e13f3f7736225b3ad3a 2e92acd77cd2000b6fc6aa52d5ed17d1 1
16 16 008291b4409b5e13f3f7736225b3ad3a 3e0e728d7726545c032cc377d2462cd7 1
17 17 008291b4409b5e13f3f7736225b3ad3a 5347327ea3c849437ea6198bdec59020 1
18 18 009cdc658da01828d21df27f296e4972 200faf822ca87c106924ef5bb5fd298a 1
19 19 009cdc658da01828d21df27f296e4972 316559694fb1092a11c34f771294dfbc 1
20 20 009cdc658da01828d21df27f296e4972 4d1682728518159f9177e18e46bbab36 1
21 21 009cdc658da01828d21df27f296e4972 4dab44c1a12a70ab4c599a324e7a8c36 1
22 22 009cdc658da01828d21df27f296e4972 4fc3a306227c71cf671686e0d125aae7 1
23 23 009cdc658da01828d21df27f296e4972 ac6e5aa7225e3f910cf6ab86c784c319 1
24 24 009cdc658da01828d21df27f296e4972 c04ebdcfcd83a6ca73477d04df18634a 1
25 25 009cdc658da01828d21df27f296e4972 fa9fa32fbe20cc9cd18f4684e11389b8 1
26 26 00aaa39411159cae13b4df983f4e0484 00aaa39411159cae13b4df983f4e0484 2
27 27 00aaa39411159cae13b4df983f4e0484 0ac467c0d08f127c511a2744764bcad2 1
28 28 00aaa39411159cae13b4df983f4e0484 14fed510355a87154cdc920d5b970896 1
29 29 00aaa39411159cae13b4df983f4e0484 1d431d87a79ec32bdc12f974bc9ba127 1
... ... ... ... ...
78936 78936 ffb59f96099d717573122fccaa7590af 1683e3dc79d6011d8080db9d54c5528d 2
78937 78937 ffb59f96099d717573122fccaa7590af 22a05ea516686518c3cca182643eb91e 1
78938 78938 ffb59f96099d717573122fccaa7590af 4edecfde3a00ce1911f5ae52522fead4 1
78939 78939 ffb59f96099d717573122fccaa7590af 60d6ebf538c4692aee854c79f80dedd4 1
78940 78940 ffb59f96099d717573122fccaa7590af 7c4ac00a7f2a7ddb47869f673cd9699b 1
78941 78941 ffb59f96099d717573122fccaa7590af a50fcb700523f59e072eefdb83635160 1
78942 78942 ffb59f96099d717573122fccaa7590af c13476f40cc86ef41f0f6a19da07dd6b 1
78943 78943 ffb59f96099d717573122fccaa7590af cb0a8c0d5af8b3a26b7e6d27ed2c219a 1
78944 78944 ffb59f96099d717573122fccaa7590af d3e5879308f36e2df25a6ec945eb5cf9 1
78945 78945 ffb59f96099d717573122fccaa7590af f7e82f41719f4f32d911c07b6e20b5e1 1
78946 78946 ffb59f96099d717573122fccaa7590af fab4fde8feaa4a10df95f7e9cb901d27 1
78947 78947 ffb59f96099d717573122fccaa7590af ffb59f96099d717573122fccaa7590af 2
78948 78948 ffb7f7b16b98f09be86d364102f88d84 0467225c437a527e7740411bf01d4138 1
78949 78949 ffb7f7b16b98f09be86d364102f88d84 4382c86dab4342a066e4addcf74f08c2 1
78950 78950 ffb7f7b16b98f09be86d364102f88d84 55b1531e5b1a9ee6f73a9d7a2751ca8b 1
78951 78951 ffb7f7b16b98f09be86d364102f88d84 69383159ca77d693b8798e4ee2ba587b 1
78952 78952 ffb7f7b16b98f09be86d364102f88d84 764691da35bc1fdb20890d164d06d236 1
78953 78953 ffb7f7b16b98f09be86d364102f88d84 816fcbe9c152c20ded6ae6f186142124 1
78954 78954 ffb7f7b16b98f09be86d364102f88d84 b672041f7e844dad58c160ffa4f2df5d 1
78955 78955 ffb7f7b16b98f09be86d364102f88d84 b7cf7b6e750c0dfbe513a6f55896bf88 1
78956 78956 ffb7f7b16b98f09be86d364102f88d84 bcfacc683a5ba2847c49936a3d0f8421 1
78957 78957 ffb7f7b16b98f09be86d364102f88d84 d8704da0f23e95c3a77b1ae101e20ca2 1
78958 78958 ffb7f7b16b98f09be86d364102f88d84 f5a48af7977e5425139ec9209db7e53b 1
78959 78959 ffb7f7b16b98f09be86d364102f88d84 fab4fde8feaa4a10df95f7e9cb901d27 1
78960 78960 ffb7f7b16b98f09be86d364102f88d84 ffb7f7b16b98f09be86d364102f88d84 1
78961 78961 ffd8d1027d813fc8c820ceff7f8195a5 78ce3688042e05d2e2bf8fa2ffcce621 1
78962 78962 ffd8d1027d813fc8c820ceff7f8195a5 fab4fde8feaa4a10df95f7e9cb901d27 1
78963 78963 ffdfd68449fbb8d11302cfdd1188ffd5 0ac467c0d08f127c511a2744764bcad2 1
78964 78964 ffdfd68449fbb8d11302cfdd1188ffd5 3db7a88dd8a8ebc2532f525f1262546c 1
78965 78965 ffdfd68449fbb8d11302cfdd1188ffd5 947bc5f562c0fd92d3927843aca79c4e 1

78966 rows × 4 columns


In [27]:
contrib2keep = voter2contribvote.groupby("Id anonymise de l'Auteur md5").count().sort('Real identifiant', ascending=False).head(30)

In [28]:
contrib2keep.head(5)


Out[28]:
Id anonymise du votant md5 Real identifiant
Id anonymise de l'Auteur md5
6061c91729e6cc8852c84b1d5e52d780 5606 5606
60a91aaec52bd85ad7250c862857eb42 4043 4043
cad1bfc92fdae2f04875ceb989d4e544 2859 2859
b12a15d8f3ca2e0f029512e9c718f15c 2648 2648
aaaa0a618d3dc7e7d2380e580b64ec7a 2634 2634

In [29]:
contrib2keep.transpose()


Out[29]:
Id anonymise de l'Auteur md5 6061c91729e6cc8852c84b1d5e52d780 60a91aaec52bd85ad7250c862857eb42 cad1bfc92fdae2f04875ceb989d4e544 b12a15d8f3ca2e0f029512e9c718f15c aaaa0a618d3dc7e7d2380e580b64ec7a e88d1b603e19a4097cef3c96088ea548 d0263a67f578edb1ae620b2293935134 3c5feceac3d93f45d1739e93545aafe1 189b40cc73eaba64c1d2a6de47e29d53 6f55b6778fe3f6d92d746222222b2c8b f0083a86e84c368ca0b4bccd4c447415 b82b6bd206994287c032f8651b7e92ed bcbfd15082682e0be238aaafa1529b63 c8462ee355300c0e28a0e0433ab3b335 30d690455ebf223af7f6b96d14325fb6 cdbd6ec745ea0f4b4e2bb18aca5dd7ce 300ae0735cef89730b15c78de6303ef6 cf5abb3d42e57eae7773cb84ba172fe6 f0167daee41b4bf92894629adeece263 bea597059e935e962f77f481079eb27f ac006fd004c8647567066970827277ba f8370933e09d1ee7c23ccd91275a2f23 a8b2f48a1c25de1869ea04fc9bf67551 f47c3f1650078e3c40efef31e952b622 9747667df6fb5be03280a4dc78c0fed3 c6bdc59c0544658230125e2d6af1a447 fd3abc7b9bbda4ad39d8fb58f168e97a 81ba64b3259284e18e06cfde00cedf68 55c3dfd4ec935706951a8af962c9ade4 a4dde51891d26844246c4123ff5096c3
Id anonymise du votant md5 5606 4043 2859 2648 2634 2012 1827 1822 1705 1633 1539 1036 1021 840 823 770 650 640 584 582 565 550 536 527 517 511 481 453 418 418
Real identifiant 5606 4043 2859 2648 2634 2012 1827 1822 1705 1633 1539 1036 1021 840 823 770 650 640 584 582 565 550 536 527 517 511 481 453 418 418

In [30]:
def HowManyVoteFromHimToContrib(voter, author):
    #res = voter2contrib.groupby(["Id anonymise de l'Auteur md5", 'Id anonymise du votant md5']).count()
    res = voter2contrib[(voter2contrib["Id anonymise de l'Auteur md5"]==author) & (voter2contrib['Id anonymise du votant md5']==voter)]
    return res.count().get_value(0,3)

In [31]:
HowManyVoteFromHimToContrib('ab9ecaf95088188b76b006cdc8a3f761','dabb33d33b0c2215d32b5115ab670770')


Out[31]:
1

In [32]:
votes.head(5)


Out[32]:
Id anonymise de l'Auteur md5 Catégorie Lié à : Type de contenu Id Content
692 ace27604697eb998a4b9177584fba8ae Mitigé Proposition "79" Proposition 79
693 e43ff226a1a03efb0682c655581808e9 Mitigé Proposition "73" Proposition 73
694 4867b6518cea7f0cd4fbe823dcbcddee Mitigé Proposition "68" Proposition 68
695 f2ec0c3c46b8814f0c531a4838271f08 Mitigé Proposition "79" Proposition 79
696 7191b5f27b6773e60813616e6838fcf9 Mitigé Proposition "73" Proposition 73

Consolidate


In [48]:
users.head(5)


Out[48]:
Id anonymise de l'Auteur md5
0 c2978e56db5048ed367624d9e78a5091
1 cab6a5eff98dd29e399209300332ed5b
2 8f454b28b7fec5b96bb60990b71e29a0
3 b0b89231cc8b63c29e0ac29a8c0c215c
5 d1631121af7c58eedc00a8ed194aae1a

In [156]:
%timeit
i=1
name_field = "vote4contrib_%s" % i
author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-156-af71f00fbc2a> in <module>()
      3 name_field = "vote4contrib_%s" % i
      4 author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
----> 5 users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))

/usr/lib/python2.7/dist-packages/pandas/core/series.pyc in map(self, arg, na_action)
   2006                                      index=self.index).__finalize__(self)
   2007         else:
-> 2008             mapped = map_f(values, arg)
   2009             return self._constructor(mapped,
   2010                                      index=self.index).__finalize__(self)

/usr/lib/python2.7/dist-packages/pandas/lib.so in pandas.lib.map_infer (pandas/lib.c:56520)()

<ipython-input-156-af71f00fbc2a> in <lambda>(x)
      3 name_field = "vote4contrib_%s" % i
      4 author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
----> 5 users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))

<ipython-input-132-6197e78e23b3> in HowManyVoteFromHimToContrib(voter, author)
      1 def HowManyVoteFromHimToContrib(voter, author):
      2     #res = voter2contrib.groupby(["Id anonymise de l'Auteur md5", 'Id anonymise du votant md5']).count()
----> 3     res = voter2contrib[(voter2contrib["Id anonymise de l'Auteur md5"]==author) & (voter2contrib['Id anonymise du votant md5']==voter)]
      4     return res.count().get_value(0,3)

/usr/lib/python2.7/dist-packages/pandas/core/ops.pyc in wrapper(self, other)
    589         else:
    590 
--> 591             mask = isnull(self)
    592 
    593             values = self.get_values()

/usr/lib/python2.7/dist-packages/pandas/core/common.pyc in isnull(obj)
    204     pandas.notnull: boolean inverse of pandas.isnull
    205     """
--> 206     return _isnull(obj)
    207 
    208 

/usr/lib/python2.7/dist-packages/pandas/core/common.pyc in _isnull_new(obj)
    214         raise NotImplementedError("isnull is not defined for MultiIndex")
    215     elif isinstance(obj, (ABCSeries, np.ndarray, pd.Index)):
--> 216         return _isnull_ndarraylike(obj)
    217     elif isinstance(obj, ABCGeneric):
    218         return obj._constructor(obj._data.isnull(func=isnull))

/usr/lib/python2.7/dist-packages/pandas/core/common.pyc in _isnull_ndarraylike(obj)
    297             else:
    298                 result = np.empty(shape, dtype=bool)
--> 299                 vec = lib.isnullobj(values.ravel())
    300                 result[...] = vec.reshape(shape)
    301 

KeyboardInterrupt: 

In [152]:
for i in range(0,30):
    print i
    name_field = "vote4contrib_%s" % i
    author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
    users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))


0
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-152-c95b6015df05> in <module>()
      3     name_field = "vote4contrib_%s" % i
      4     author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
----> 5     users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))

/usr/lib/python2.7/dist-packages/pandas/core/series.pyc in map(self, arg, na_action)
   2006                                      index=self.index).__finalize__(self)
   2007         else:
-> 2008             mapped = map_f(values, arg)
   2009             return self._constructor(mapped,
   2010                                      index=self.index).__finalize__(self)

/usr/lib/python2.7/dist-packages/pandas/lib.so in pandas.lib.map_infer (pandas/lib.c:56520)()

<ipython-input-152-c95b6015df05> in <lambda>(x)
      3     name_field = "vote4contrib_%s" % i
      4     author = contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(i)
----> 5     users[name_field] = users["Id anonymise de l'Auteur md5"].map(lambda x: HowManyVoteFromHimToContrib(x, author))

<ipython-input-132-6197e78e23b3> in HowManyVoteFromHimToContrib(voter, author)
      1 def HowManyVoteFromHimToContrib(voter, author):
      2     #res = voter2contrib.groupby(["Id anonymise de l'Auteur md5", 'Id anonymise du votant md5']).count()
----> 3     res = voter2contrib[(voter2contrib["Id anonymise de l'Auteur md5"]==author) & (voter2contrib['Id anonymise du votant md5']==voter)]
      4     return res.count().get_value(0,3)

/usr/lib/python2.7/dist-packages/pandas/core/ops.pyc in wrapper(self, other)
    598 
    599             # scalars
--> 600             res = na_op(values, other)
    601             if np.isscalar(res):
    602                 raise TypeError('Could not compare %s type with Series'

/usr/lib/python2.7/dist-packages/pandas/core/ops.pyc in na_op(x, y)
    556                     result = lib.vec_compare(x, y, op)
    557             else:
--> 558                 result = lib.scalar_compare(x, y, op)
    559         else:
    560 

KeyboardInterrupt: 

In [147]:
contrib2keep.reset_index()["Id anonymise de l'Auteur md5"].get_value(2)


Out[147]:
u'cad1bfc92fdae2f04875ceb989d4e544'

In [149]:
users.head(5)


Out[149]:
Id anonymise de l'Auteur md5
0 c2978e56db5048ed367624d9e78a5091
1 cab6a5eff98dd29e399209300332ed5b
2 8f454b28b7fec5b96bb60990b71e29a0
3 b0b89231cc8b63c29e0ac29a8c0c215c
5 d1631121af7c58eedc00a8ed194aae1a

Let's do a K-Means


In [1]:
from sklearn.cluster import KMeans

In [78]:
dataset = users

In [ ]:


In [77]:
kmeans = KMeans

In [79]:
kmeans.fit(dataset)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-79-32d15abcc92d> in <module>()
----> 1 kmeans.fit(dataset)

TypeError: unbound method fit() must be called with KMeans instance as first argument (got DataFrame instance instead)

In [ ]:

NetworkX


In [33]:
import networkx as nx
import community

In [35]:
VoteGraph = nx.from_pandas_dataframe(votes, "Id anonymise de l'Auteur md5",'Li\xc3\xa9 \xc3\xa0 :')

In [36]:
parts = community.best_partition(VoteGraph)

In [37]:
values = [parts.get(node) for node in VoteGraph.nodes()]

In [38]:
import matplotlib.pyplot as plt

In [39]:
%matplotlib inline

In [41]:
partition = community.best_partition(VoteGraph)

In [47]:
UserCom = pd.DataFrame(partition.items(), columns=['UserId','Community'])

In [48]:
UserCom.head(5)


Out[48]:
UserId Community
0 5f7215c6e137b20911c14086711510fc 4
1 700c05ed1775a8700589737094ae812d 17
2 Argument "5261" 0
3 ff1abcbf477045f3aa54587b6d0187b6 0
4 0f31e1936d6bc55d94864d3fad9c5657 1

In [56]:
UserCom.groupby('Community').count().sort('UserId', ascending=False)


Out[56]:
UserId
Community
0 4523
8 4458
1 3910
5 3534
4 3167
2 2806
10 990
7 879
6 812
13 716
14 433
9 414
3 258
12 159
17 105
16 105
11 89
18 51
19 39
20 31
22 23
15 10
24 10
21 6
29 4
27 3
23 2
25 2
26 2
28 2
30 2
31 2
32 2

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [46]:
#drawing
size = float(len(set(partition.values())))
pos = nx.spring_layout(VoteGraph)
count = 0.
for com in set(partition.values()) :
    count = count + 1.
    list_nodes = [nodes for nodes in partition.keys()
                                if partition[nodes] == com]
    nx.draw_networkx_nodes(VoteGraph, pos, list_nodes, node_size = 20,
                                node_color = str(count / size))


nx.draw_networkx_edges(VoteGraph,pos, alpha=0.5)
plt.show()


---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-46-1e20f01c4cd4> in <module>()
      1 #drawing
      2 size = float(len(set(partition.values())))
----> 3 pos = nx.spring_layout(VoteGraph)
      4 count = 0.
      5 for com in set(partition.values()) :

/home/tarnefys/.local/lib/python2.7/site-packages/networkx/drawing/layout.pyc in fruchterman_reingold_layout(G, dim, k, pos, fixed, iterations, weight, scale, center)
    298         pos = _sparse_fruchterman_reingold(A, dim, k, pos_arr, fixed, iterations)
    299     except:
--> 300         A = nx.to_numpy_matrix(G,weight=weight)
    301         if k is None and fixed is not None:
    302            # We must adjust k by domain size for layouts that are not near 1x1

/home/tarnefys/.local/lib/python2.7/site-packages/networkx/convert_matrix.pyc in to_numpy_matrix(G, nodelist, dtype, order, multigraph_weight, weight, nonedge)
    367     else:
    368         # Graph or DiGraph, this is much faster than above
--> 369         M = np.zeros((nlen,nlen), dtype=dtype, order=order) + np.nan
    370         for u,nbrdict in G.adjacency_iter():
    371             for v,d in nbrdict.items():

MemoryError: 

In [ ]: