{ "cells": [ { "cell_type": "code", "execution_count": 40, "metadata": { "ExecuteTime": { "end_time": "2019-03-07T02:56:32.521682Z", "start_time": "2019-03-07T02:56:26.288106Z" } }, "outputs": [], "source": [ "import pandas as pd, numpy as np, json, os\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "plt.style.use('seaborn-whitegrid')" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "#!pip install d3IpyPlus\n", "from d3IpyPlus import ScatterPlot, LinePlot, BarPlot, StackedArea" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "#!pip install pyecharts" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "m=json.loads(open('ignore/member_timelines.json','r').read())\n", "members=json.loads(open('ignore/member_simple.json','r').read())" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "d=pd.DataFrame(members['deaths'],index=['v']).T" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "d['v']=' †'" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "s=pd.DataFrame(members['s2'],index=['s']).T\n", "s=s.join(d)\n", "s['v']=s['v'].fillna('')\n", "s['s']=s['s']+s['v']\n", "s=s[['s']]\n", "s['w']=s['s'].str.split(' ').str[0].str[0]+s['s'].str.split(' ').str[-1].str[0]" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "szd_color='#E91C62'" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "pcolors=json.loads(open('json/pcolors.json','r').read())" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Megye
Arama Viorel | 1938-03-10🇷🇴 Bákó
Pop Petru | 1939-03-01🇷🇴 Argeș
Les Ioan | 1947-09-01🇷🇴 Szeben
Carp Mihai | 1956-05-20🇷🇴 Bihar
Craciun Gheorghe | 1954-12-13🇷🇴 Olt
\n", "
" ], "text/plain": [ " Megye \n", "Arama Viorel | 1938-03-10 🇷🇴 Bákó\n", "Pop Petru | 1939-03-01 🇷🇴 Argeș\n", "Les Ioan | 1947-09-01 🇷🇴 Szeben\n", "Carp Mihai | 1956-05-20 🇷🇴 Bihar\n", "Craciun Gheorghe | 1954-12-13 🇷🇴 Olt" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g=pd.DataFrame(members['megye'],index=['Megye ']).T\n", "g.head()" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0 %\n", "2.9080757262919126 %\n", "5.816151452583825 %\n", "8.724227178875738 %\n", "11.63230290516765 %\n", "14.540378631459564 %\n", "17.448454357751476 %\n", "20.35653008404339 %\n", "23.2646058103353 %\n", "26.172681536627213 %\n", "29.08075726291913 %\n", "31.98883298921104 %\n", "34.89690871550295 %\n", "37.804984441794865 %\n", "40.71306016808678 %\n", "43.62113589437869 %\n", "46.5292116206706 %\n", "49.43728734696251 %\n", "52.345363073254426 %\n", "55.25343879954634 %\n", "58.16151452583826 %\n", "61.06959025213017 %\n", "63.97766597842208 %\n", "66.88574170471398 %\n", "69.7938174310059 %\n", "72.70189315729782 %\n", "75.60996888358973 %\n", "78.51804460988164 %\n", "81.42612033617355 %\n", "84.33419606246547 %\n", "87.24227178875738 %\n", "90.15034751504929 %\n", "93.0584232413412 %\n", "95.96649896763311 %\n", "98.87457469392503 %\n" ] } ], "source": [ "data={}\n", "attention={}\n", "for k,i in enumerate(m):\n", " if k%1000==0: print(k/len(m)*100,'%')\n", " if i['Típus']=='Párt':\n", " if i['Csoportok'] not in data:data[i['Csoportok']]={'start':pd.to_datetime('2030'),'end':pd.to_datetime('1980')}\n", " start=pd.to_datetime(i['start'])\n", " end=pd.to_datetime(i['end'])\n", " data[i['Csoportok']]['start']=min(data[i['Csoportok']]['start'],start)\n", " data[i['Csoportok']]['end']=max(data[i['Csoportok']]['end'],end)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "part_timelines=pd.DataFrame(data).T\n", "part_timelines.index.name='id'" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "part_timelines['start']=part_timelines['start'].astype(str).str[:10]\n", "part_timelines['end']=part_timelines['end'].astype(str).str[:10]" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "p=part_timelines.reset_index()[['id']]\n", "p['Color']=p['id'].str.split(' ').str[1].str.strip()\n", "p['Part']=p['id'].str.split('-').str[0].str.strip()" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "part_timelines=part_timelines.join(p.set_index('id').drop_duplicates())" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [], "source": [ "logos={'🕊️':'ALDE', '🌹':'PSD', '📐':'PNL', '🔶':'PD', '⚛️':'PP-DD', '👤':'Independent', '⚪️':'FSN',\n", " '✳️':'PNTCD', '🔱':'PRM', '🌷':'RMDSZ', '🍀':'ECO', '🍏':'PMP',\n", " '🔷':'USR', '🦅':'UNPR', '🔘':'Mas'}" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "part_timelines['logo']=part_timelines['Part'].str.split(' ').str[0]" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [], "source": [ "part_timelines['group']=[logos[i] for i in part_timelines['logo'].values]\n", "part_timelines['label']=[i+' '+logos[i] for i in part_timelines['logo'].values]" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "pcolors=json.loads(open('json/pcolors.json','r').read())" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "part_timelines=part_timelines.join(pd.DataFrame(pcolors,index=['cvalue']).T,on='group').fillna('grey')" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
endstartColorPartlogogrouplabelcvalue
id
🔱 PRM - Partidul România Mare2008-12-131992-10-21PRM🔱 PRM🔱PRM🔱 PRM#0d5ca4
✳️ PNTCD - Partidul Naţional Ţărănesc Creştin Democrat2014-03-011990-06-18PNTCD✳️ PNTCD✳️PNTCD✳️ PNTCD#04843c
📐 PAC - Partidul Alianţei Civice1996-11-221992-10-21PAC📐 PAC📐PNL📐 PNL#f4d42c
📐 PNL - Partidul Naţional Liberal2019-07-011990-06-18PNL📐 PNL📐PNL📐 PNL#f4d42c
🔶 PDL - Partidul Democrat Liberal2015-02-012004-12-17PDL🔶 PDL🔶PD🔶 PDdarkOrange
⚪️ FSN - Frontul Salvării Naţionale1994-05-231990-06-18FSN⚪️ FSN⚪️FSN⚪️ FSNgrey
🔶 PD - Partidul Democrat2008-12-131992-10-26PD🔶 PD🔶PD🔶 PDdarkOrange
🌹 PSM - Partidul Socialist al Muncii1996-11-221992-10-21PSM🌹 PSM🌹PSD🌹 PSD#dc2c24
🌷 RMDSZ - Romániai Magyar Demokrata Szövetség2019-07-011990-06-18RMDSZ🌷 RMDSZ🌷RMDSZ🌷 RMDSZgreen
🌹 PSD - Partidul Social Democrat2019-07-012000-12-15PSD🌹 PSD🌹PSD🌹 PSD#dc2c24
👤 Independent - Independent2019-07-011990-06-18Independent👤 Independent👤Independent👤 Independent#555
🕊️ ALDE - Partidul Alianţa Liberalilor şi Democraţilor2019-07-012016-12-21ALDE🕊️ ALDE🕊️ALDE🕊️ ALDE#046cab
🌹 PDSR - Partidul Democraţiei Sociale din România2001-06-011992-10-26PDSR🌹 PDSR🌹PSD🌹 PSD#dc2c24
🔷 USR - Uniunea Salvaţi România2019-07-012016-12-21USR🔷 USR🔷USR🔷 USR#04abe4
🕊️ PUR-SL - Partidul Umanist din România2005-05-012000-12-15PUR-SL🕊️ PUR🕊️ALDE🕊️ ALDE#046cab
⚛️ PP-DD - Partidul Poporului Dan Diaconescu2015-08-012012-12-20PP-DD⚛️ PP⚛️PP-DD⚛️ PP-DD#9966cc
🦅 UNPR - Uniunea Naţională pentru Progresul României2016-12-212012-12-20UNPR🦅 UNPR🦅UNPR🦅 UNPR#a8190f
📐 PNL-CD - Partidul Naţional Liberal2000-11-301992-10-21PNL-CD📐 PNL📐PNL📐 PNL#f4d42c
🕊️ PC - Partidul Conservator2016-12-212004-12-17PC🕊️ PC🕊️ALDE🕊️ ALDE#046cab
🕊️ PUNR - Partidul Unităţii Naţionale Române2000-11-301990-06-18PUNR🕊️ PUNR🕊️ALDE🕊️ ALDE#046cab
📐 PL'93 - Partidul Liberal1996-11-221992-10-28PL'93📐 PL'93📐PNL📐 PNL#f4d42c
⚪️ FDSN - Frontul Democrat al Salvarii Nationale1993-07-011990-06-18FDSN⚪️ FDSN⚪️FSN⚪️ FSNgrey
🍏 PMP - Partidul Mişcarea Populară2019-07-012016-12-21PMP🍏 PMP🍏PMP🍏 PMP#0484cc
🔘 PTLDR - Partidul Tineretului Liber Democrat din România1992-10-161990-06-18PTLDR🔘 PTLDR🔘Mas🔘 Mas#777
🔘 PLS - Partidul Liber Schimbist1992-10-161990-06-18PLS🔘 PLS🔘Mas🔘 Mas#777
🌹 PSDR - Partidul Socialist Democratic din România2001-06-011990-06-18PSDR🌹 PSDR🌹PSD🌹 PSD#dc2c24
🍀 PER - Partidul Ecologist Român2000-11-301990-06-18PER🍀 PER🍀ECO🍀 ECO#69a54f
🔘 PAR - Partidul Alternativa României2000-11-301996-11-27PAR🔘 PAR🔘Mas🔘 Mas#777
🔘 FC - Forţa Civică2015-07-012012-12-20FC🔘 FC🔘Mas🔘 Mas#777
🍀 PDAR - Partidul Democrat Agrar din România1996-11-221990-06-18PDAR🍀 PDAR🍀ECO🍀 ECO#69a54f
🔘 PRNR - Partidul Reconstrucţiei Naţionale din România1992-10-161990-06-18PRNR🔘 PRNR🔘Mas🔘 Mas#777
🍀 MER - Mişcarea Ecologistă din România1992-10-161990-06-18MER🍀 MER🍀ECO🍀 ECO#69a54f
📐 PNL-AT - Partidul Naţional Liberal1993-02-251992-10-21PNL-AT📐 PNL📐PNL📐 PNL#f4d42c
🍀 FER - Federaţia Ecologistă Română2000-11-301996-11-27FER🍀 FER🍀ECO🍀 ECO#69a54f
🔘 GDC - Gruparea Democratică de Centru1992-10-161990-06-18GDC🔘 GDC🔘Mas🔘 Mas#777
🔘 AUR - Alianţa pentru Unitatea Românilor1992-10-161990-06-18AUR🔘 AUR🔘Mas🔘 Mas#777
🔘 PDM - Partidul Democrat al Muncii1992-10-161990-06-18PDM🔘 PDM🔘Mas🔘 Mas#777
🔘 ULB - Uniunea Liberală \"Brătianu\"1992-10-161990-06-18ULB🔘 ULB🔘Mas🔘 Mas#777
👤 Minorități - Minorități2019-07-012016-12-21Minorități👤 Minorități👤Independent👤 Independent#555
\n", "
" ], "text/plain": [ " end start \\\n", "id \n", "🔱 PRM - Partidul România Mare 2008-12-13 1992-10-21 \n", "✳️ PNTCD - Partidul Naţional Ţărănesc Creştin D... 2014-03-01 1990-06-18 \n", "📐 PAC - Partidul Alianţei Civice 1996-11-22 1992-10-21 \n", "📐 PNL - Partidul Naţional Liberal 2019-07-01 1990-06-18 \n", "🔶 PDL - Partidul Democrat Liberal 2015-02-01 2004-12-17 \n", "⚪️ FSN - Frontul Salvării Naţionale 1994-05-23 1990-06-18 \n", "🔶 PD - Partidul Democrat 2008-12-13 1992-10-26 \n", "🌹 PSM - Partidul Socialist al Muncii 1996-11-22 1992-10-21 \n", "🌷 RMDSZ - Romániai Magyar Demokrata Szövetség 2019-07-01 1990-06-18 \n", "🌹 PSD - Partidul Social Democrat 2019-07-01 2000-12-15 \n", "👤 Independent - Independent 2019-07-01 1990-06-18 \n", "🕊️ ALDE - Partidul Alianţa Liberalilor şi Democ... 2019-07-01 2016-12-21 \n", "🌹 PDSR - Partidul Democraţiei Sociale din România 2001-06-01 1992-10-26 \n", "🔷 USR - Uniunea Salvaţi România 2019-07-01 2016-12-21 \n", "🕊️ PUR-SL - Partidul Umanist din România 2005-05-01 2000-12-15 \n", "⚛️ PP-DD - Partidul Poporului Dan Diaconescu 2015-08-01 2012-12-20 \n", "🦅 UNPR - Uniunea Naţională pentru Progresul Rom... 2016-12-21 2012-12-20 \n", "📐 PNL-CD - Partidul Naţional Liberal 2000-11-30 1992-10-21 \n", "🕊️ PC - Partidul Conservator 2016-12-21 2004-12-17 \n", "🕊️ PUNR - Partidul Unităţii Naţionale Române 2000-11-30 1990-06-18 \n", "📐 PL'93 - Partidul Liberal 1996-11-22 1992-10-28 \n", "⚪️ FDSN - Frontul Democrat al Salvarii Nationale 1993-07-01 1990-06-18 \n", "🍏 PMP - Partidul Mişcarea Populară 2019-07-01 2016-12-21 \n", "🔘 PTLDR - Partidul Tineretului Liber Democrat d... 1992-10-16 1990-06-18 \n", "🔘 PLS - Partidul Liber Schimbist 1992-10-16 1990-06-18 \n", "🌹 PSDR - Partidul Socialist Democratic din România 2001-06-01 1990-06-18 \n", "🍀 PER - Partidul Ecologist Român 2000-11-30 1990-06-18 \n", "🔘 PAR - Partidul Alternativa României 2000-11-30 1996-11-27 \n", "🔘 FC - Forţa Civică 2015-07-01 2012-12-20 \n", "🍀 PDAR - Partidul Democrat Agrar din România 1996-11-22 1990-06-18 \n", "🔘 PRNR - Partidul Reconstrucţiei Naţionale din ... 1992-10-16 1990-06-18 \n", "🍀 MER - Mişcarea Ecologistă din România 1992-10-16 1990-06-18 \n", "📐 PNL-AT - Partidul Naţional Liberal 1993-02-25 1992-10-21 \n", "🍀 FER - Federaţia Ecologistă Română 2000-11-30 1996-11-27 \n", "🔘 GDC - Gruparea Democratică de Centru 1992-10-16 1990-06-18 \n", "🔘 AUR - Alianţa pentru Unitatea Românilor 1992-10-16 1990-06-18 \n", "🔘 PDM - Partidul Democrat al Muncii 1992-10-16 1990-06-18 \n", "🔘 ULB - Uniunea Liberală \"Brătianu\" 1992-10-16 1990-06-18 \n", "👤 Minorități - Minorități 2019-07-01 2016-12-21 \n", "\n", " Color \\\n", "id \n", "🔱 PRM - Partidul România Mare PRM \n", "✳️ PNTCD - Partidul Naţional Ţărănesc Creştin D... PNTCD \n", "📐 PAC - Partidul Alianţei Civice PAC \n", "📐 PNL - Partidul Naţional Liberal PNL \n", "🔶 PDL - Partidul Democrat Liberal PDL \n", "⚪️ FSN - Frontul Salvării Naţionale FSN \n", "🔶 PD - Partidul Democrat PD \n", "🌹 PSM - Partidul Socialist al Muncii PSM \n", "🌷 RMDSZ - Romániai Magyar Demokrata Szövetség RMDSZ \n", "🌹 PSD - Partidul Social Democrat PSD \n", "👤 Independent - Independent Independent \n", "🕊️ ALDE - Partidul Alianţa Liberalilor şi Democ... ALDE \n", "🌹 PDSR - Partidul Democraţiei Sociale din România PDSR \n", "🔷 USR - Uniunea Salvaţi România USR \n", "🕊️ PUR-SL - Partidul Umanist din România PUR-SL \n", "⚛️ PP-DD - Partidul Poporului Dan Diaconescu PP-DD \n", "🦅 UNPR - Uniunea Naţională pentru Progresul Rom... UNPR \n", "📐 PNL-CD - Partidul Naţional Liberal PNL-CD \n", "🕊️ PC - Partidul Conservator PC \n", "🕊️ PUNR - Partidul Unităţii Naţionale Române PUNR \n", "📐 PL'93 - Partidul Liberal PL'93 \n", "⚪️ FDSN - Frontul Democrat al Salvarii Nationale FDSN \n", "🍏 PMP - Partidul Mişcarea Populară PMP \n", "🔘 PTLDR - Partidul Tineretului Liber Democrat d... PTLDR \n", "🔘 PLS - Partidul Liber Schimbist PLS \n", "🌹 PSDR - Partidul Socialist Democratic din România PSDR \n", "🍀 PER - Partidul Ecologist Român PER \n", "🔘 PAR - Partidul Alternativa României PAR \n", "🔘 FC - Forţa Civică FC \n", "🍀 PDAR - Partidul Democrat Agrar din România PDAR \n", "🔘 PRNR - Partidul Reconstrucţiei Naţionale din ... PRNR \n", "🍀 MER - Mişcarea Ecologistă din România MER \n", "📐 PNL-AT - Partidul Naţional Liberal PNL-AT \n", "🍀 FER - Federaţia Ecologistă Română FER \n", "🔘 GDC - Gruparea Democratică de Centru GDC \n", "🔘 AUR - Alianţa pentru Unitatea Românilor AUR \n", "🔘 PDM - Partidul Democrat al Muncii PDM \n", "🔘 ULB - Uniunea Liberală \"Brătianu\" ULB \n", "👤 Minorități - Minorități Minorități \n", "\n", " Part logo \\\n", "id \n", "🔱 PRM - Partidul România Mare 🔱 PRM 🔱 \n", "✳️ PNTCD - Partidul Naţional Ţărănesc Creştin D... ✳️ PNTCD ✳️ \n", "📐 PAC - Partidul Alianţei Civice 📐 PAC 📐 \n", "📐 PNL - Partidul Naţional Liberal 📐 PNL 📐 \n", "🔶 PDL - Partidul Democrat Liberal 🔶 PDL 🔶 \n", "⚪️ FSN - Frontul Salvării Naţionale ⚪️ FSN ⚪️ \n", "🔶 PD - Partidul Democrat 🔶 PD 🔶 \n", "🌹 PSM - Partidul Socialist al Muncii 🌹 PSM 🌹 \n", "🌷 RMDSZ - Romániai Magyar Demokrata Szövetség 🌷 RMDSZ 🌷 \n", "🌹 PSD - Partidul Social Democrat 🌹 PSD 🌹 \n", "👤 Independent - Independent 👤 Independent 👤 \n", "🕊️ ALDE - Partidul Alianţa Liberalilor şi Democ... 🕊️ ALDE 🕊️ \n", "🌹 PDSR - Partidul Democraţiei Sociale din România 🌹 PDSR 🌹 \n", "🔷 USR - Uniunea Salvaţi România 🔷 USR 🔷 \n", "🕊️ PUR-SL - Partidul Umanist din România 🕊️ PUR 🕊️ \n", "⚛️ PP-DD - Partidul Poporului Dan Diaconescu ⚛️ PP ⚛️ \n", "🦅 UNPR - Uniunea Naţională pentru Progresul Rom... 🦅 UNPR 🦅 \n", "📐 PNL-CD - Partidul Naţional Liberal 📐 PNL 📐 \n", "🕊️ PC - Partidul Conservator 🕊️ PC 🕊️ \n", "🕊️ PUNR - Partidul Unităţii Naţionale Române 🕊️ PUNR 🕊️ \n", "📐 PL'93 - Partidul Liberal 📐 PL'93 📐 \n", "⚪️ FDSN - Frontul Democrat al Salvarii Nationale ⚪️ FDSN ⚪️ \n", "🍏 PMP - Partidul Mişcarea Populară 🍏 PMP 🍏 \n", "🔘 PTLDR - Partidul Tineretului Liber Democrat d... 🔘 PTLDR 🔘 \n", "🔘 PLS - Partidul Liber Schimbist 🔘 PLS 🔘 \n", "🌹 PSDR - Partidul Socialist Democratic din România 🌹 PSDR 🌹 \n", "🍀 PER - Partidul Ecologist Român 🍀 PER 🍀 \n", "🔘 PAR - Partidul Alternativa României 🔘 PAR 🔘 \n", "🔘 FC - Forţa Civică 🔘 FC 🔘 \n", "🍀 PDAR - Partidul Democrat Agrar din România 🍀 PDAR 🍀 \n", "🔘 PRNR - Partidul Reconstrucţiei Naţionale din ... 🔘 PRNR 🔘 \n", "🍀 MER - Mişcarea Ecologistă din România 🍀 MER 🍀 \n", "📐 PNL-AT - Partidul Naţional Liberal 📐 PNL 📐 \n", "🍀 FER - Federaţia Ecologistă Română 🍀 FER 🍀 \n", "🔘 GDC - Gruparea Democratică de Centru 🔘 GDC 🔘 \n", "🔘 AUR - Alianţa pentru Unitatea Românilor 🔘 AUR 🔘 \n", "🔘 PDM - Partidul Democrat al Muncii 🔘 PDM 🔘 \n", "🔘 ULB - Uniunea Liberală \"Brătianu\" 🔘 ULB 🔘 \n", "👤 Minorități - Minorități 👤 Minorități 👤 \n", "\n", " group \\\n", "id \n", "🔱 PRM - Partidul România Mare PRM \n", "✳️ PNTCD - Partidul Naţional Ţărănesc Creştin D... PNTCD \n", "📐 PAC - Partidul Alianţei Civice PNL \n", "📐 PNL - Partidul Naţional Liberal PNL \n", "🔶 PDL - Partidul Democrat Liberal PD \n", "⚪️ FSN - Frontul Salvării Naţionale FSN \n", "🔶 PD - Partidul Democrat PD \n", "🌹 PSM - Partidul Socialist al Muncii PSD \n", "🌷 RMDSZ - Romániai Magyar Demokrata Szövetség RMDSZ \n", "🌹 PSD - Partidul Social Democrat PSD \n", "👤 Independent - Independent Independent \n", "🕊️ ALDE - Partidul Alianţa Liberalilor şi Democ... ALDE \n", "🌹 PDSR - Partidul Democraţiei Sociale din România PSD \n", "🔷 USR - Uniunea Salvaţi România USR \n", "🕊️ PUR-SL - Partidul Umanist din România ALDE \n", "⚛️ PP-DD - Partidul Poporului Dan Diaconescu PP-DD \n", "🦅 UNPR - Uniunea Naţională pentru Progresul Rom... UNPR \n", "📐 PNL-CD - Partidul Naţional Liberal PNL \n", "🕊️ PC - Partidul Conservator ALDE \n", "🕊️ PUNR - Partidul Unităţii Naţionale Române ALDE \n", "📐 PL'93 - Partidul Liberal PNL \n", "⚪️ FDSN - Frontul Democrat al Salvarii Nationale FSN \n", "🍏 PMP - Partidul Mişcarea Populară PMP \n", "🔘 PTLDR - Partidul Tineretului Liber Democrat d... Mas \n", "🔘 PLS - Partidul Liber Schimbist Mas \n", "🌹 PSDR - Partidul Socialist Democratic din România PSD \n", "🍀 PER - Partidul Ecologist Român ECO \n", "🔘 PAR - Partidul Alternativa României Mas \n", "🔘 FC - Forţa Civică Mas \n", "🍀 PDAR - Partidul Democrat Agrar din România ECO \n", "🔘 PRNR - Partidul Reconstrucţiei Naţionale din ... Mas \n", "🍀 MER - Mişcarea Ecologistă din România ECO \n", "📐 PNL-AT - Partidul Naţional Liberal PNL \n", "🍀 FER - Federaţia Ecologistă Română ECO \n", "🔘 GDC - Gruparea Democratică de Centru Mas \n", "🔘 AUR - Alianţa pentru Unitatea Românilor Mas \n", "🔘 PDM - Partidul Democrat al Muncii Mas \n", "🔘 ULB - Uniunea Liberală \"Brătianu\" Mas \n", "👤 Minorități - Minorități Independent \n", "\n", " label cvalue \n", "id \n", "🔱 PRM - Partidul România Mare 🔱 PRM #0d5ca4 \n", "✳️ PNTCD - Partidul Naţional Ţărănesc Creştin D... ✳️ PNTCD #04843c \n", "📐 PAC - Partidul Alianţei Civice 📐 PNL #f4d42c \n", "📐 PNL - Partidul Naţional Liberal 📐 PNL #f4d42c \n", "🔶 PDL - Partidul Democrat Liberal 🔶 PD darkOrange \n", "⚪️ FSN - Frontul Salvării Naţionale ⚪️ FSN grey \n", "🔶 PD - Partidul Democrat 🔶 PD darkOrange \n", "🌹 PSM - Partidul Socialist al Muncii 🌹 PSD #dc2c24 \n", "🌷 RMDSZ - Romániai Magyar Demokrata Szövetség 🌷 RMDSZ green \n", "🌹 PSD - Partidul Social Democrat 🌹 PSD #dc2c24 \n", "👤 Independent - Independent 👤 Independent #555 \n", "🕊️ ALDE - Partidul Alianţa Liberalilor şi Democ... 🕊️ ALDE #046cab \n", "🌹 PDSR - Partidul Democraţiei Sociale din România 🌹 PSD #dc2c24 \n", "🔷 USR - Uniunea Salvaţi România 🔷 USR #04abe4 \n", "🕊️ PUR-SL - Partidul Umanist din România 🕊️ ALDE #046cab \n", "⚛️ PP-DD - Partidul Poporului Dan Diaconescu ⚛️ PP-DD #9966cc \n", "🦅 UNPR - Uniunea Naţională pentru Progresul Rom... 🦅 UNPR #a8190f \n", "📐 PNL-CD - Partidul Naţional Liberal 📐 PNL #f4d42c \n", "🕊️ PC - Partidul Conservator 🕊️ ALDE #046cab \n", "🕊️ PUNR - Partidul Unităţii Naţionale Române 🕊️ ALDE #046cab \n", "📐 PL'93 - Partidul Liberal 📐 PNL #f4d42c \n", "⚪️ FDSN - Frontul Democrat al Salvarii Nationale ⚪️ FSN grey \n", "🍏 PMP - Partidul Mişcarea Populară 🍏 PMP #0484cc \n", "🔘 PTLDR - Partidul Tineretului Liber Democrat d... 🔘 Mas #777 \n", "🔘 PLS - Partidul Liber Schimbist 🔘 Mas #777 \n", "🌹 PSDR - Partidul Socialist Democratic din România 🌹 PSD #dc2c24 \n", "🍀 PER - Partidul Ecologist Român 🍀 ECO #69a54f \n", "🔘 PAR - Partidul Alternativa României 🔘 Mas #777 \n", "🔘 FC - Forţa Civică 🔘 Mas #777 \n", "🍀 PDAR - Partidul Democrat Agrar din România 🍀 ECO #69a54f \n", "🔘 PRNR - Partidul Reconstrucţiei Naţionale din ... 🔘 Mas #777 \n", "🍀 MER - Mişcarea Ecologistă din România 🍀 ECO #69a54f \n", "📐 PNL-AT - Partidul Naţional Liberal 📐 PNL #f4d42c \n", "🍀 FER - Federaţia Ecologistă Română 🍀 ECO #69a54f \n", "🔘 GDC - Gruparea Democratică de Centru 🔘 Mas #777 \n", "🔘 AUR - Alianţa pentru Unitatea Românilor 🔘 Mas #777 \n", "🔘 PDM - Partidul Democrat al Muncii 🔘 Mas #777 \n", "🔘 ULB - Uniunea Liberală \"Brătianu\" 🔘 Mas #777 \n", "👤 Minorități - Minorități 👤 Independent #555 " ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "part_timelines" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "part_timelines_list=list(part_timelines.reset_index().T.to_dict().values())" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9795" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "open('json/part_timelines.json','w').write(json.dumps(part_timelines_list))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Resolve for non-activity\n" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "legs={'2016':['2016-12-21','2019-07-01'],\n", "'2012':['2012-12-20','2016-12-21'],\n", "'2008':['2008-12-19','2012-12-20'],\n", "'2004':['2004-12-19','2008-12-13'],\n", "'2000':['2000-12-15','2004-11-30'],\n", "'1996':['1996-11-27','2000-11-30'],\n", "'1992':['1992-10-28','1996-11-22'],\n", "'1990':['1990-06-19','1992-10-16']}" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "switch_months=set([str(pd.to_datetime(j))[:7] for i in legs for j in legs[i]])" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "from calendar import monthrange" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0 %\n", "2.9080757262919126 %\n", "5.816151452583825 %\n", "8.724227178875738 %\n", "11.63230290516765 %\n", "14.540378631459564 %\n", "17.448454357751476 %\n", "20.35653008404339 %\n", "23.2646058103353 %\n", "26.172681536627213 %\n", "29.08075726291913 %\n", "31.98883298921104 %\n", "34.89690871550295 %\n", "37.804984441794865 %\n", "40.71306016808678 %\n", "43.62113589437869 %\n", "46.5292116206706 %\n", "49.43728734696251 %\n", "52.345363073254426 %\n", "55.25343879954634 %\n", "58.16151452583826 %\n", "61.06959025213017 %\n", "63.97766597842208 %\n", "66.88574170471398 %\n", "69.7938174310059 %\n", "72.70189315729782 %\n", "75.60996888358973 %\n", "78.51804460988164 %\n", "81.42612033617355 %\n", "84.33419606246547 %\n", "87.24227178875738 %\n", "90.15034751504929 %\n", "93.0584232413412 %\n", "95.96649896763311 %\n", "98.87457469392503 %\n" ] } ], "source": [ "data2={}\n", "parties={}\n", "for k,i in enumerate(m):\n", " if k%1000==0: print(k/len(m)*100,'%')\n", " if i['Típus']=='Párt':\n", " name=i['Name']\n", " part=i['Csoportok']\n", " if part not in parties:parties[part]=[]\n", " parties[part].append(name)\n", " if part not in data2:data2[part]={}\n", " for t in pd.date_range(i['start'],i['end']):\n", " st=str(t)[:10]\n", " if st not in data2[part]:data2[part][st]=0\n", " data2[part][st]+=1" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "df=pd.DataFrame(data2)" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [], "source": [ "df=df.stack().reset_index()\n", "df.columns=['x','id','y']" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "df=df.set_index(['id','x'])" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [], "source": [ "dqs=[]\n", "for d in df.index.get_level_values(0).unique():\n", " dq=df.loc[d]\n", " dq.index=pd.to_datetime(dq.index)\n", " dq=dq.sort_index()\n", " dq=dq.resample('1M').sum()\n", " dq['id']=d\n", " dq['month_length']=[monthrange(t.year,t.month)[1] for t in dq.index]\n", " dqs.append(dq)\n", "df=pd.concat(dqs).reset_index()" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "df=df.sort_values(by='id')" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "df['y']=df['y']/df['month_length']" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "#df=df.groupby(['id','x']).mean().rolling(12).mean().reset_index().dropna()" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "df2=df.join(part_timelines,on='id')" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "df2['x']=df2['x'].astype(str).str[:7]" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1068158" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df2=df2[df2['y']>0]\n", "values=list(df2.T.to_dict().values())\n", "open('json/part_timelines2.json','w').write(json.dumps(values))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }