{
"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",
" Megye | \n",
"
\n",
" \n",
" \n",
" \n",
" Arama Viorel | 1938-03-10 | \n",
" 🇷🇴 Bákó | \n",
"
\n",
" \n",
" Pop Petru | 1939-03-01 | \n",
" 🇷🇴 Argeș | \n",
"
\n",
" \n",
" Les Ioan | 1947-09-01 | \n",
" 🇷🇴 Szeben | \n",
"
\n",
" \n",
" Carp Mihai | 1956-05-20 | \n",
" 🇷🇴 Bihar | \n",
"
\n",
" \n",
" Craciun Gheorghe | 1954-12-13 | \n",
" 🇷🇴 Olt | \n",
"
\n",
" \n",
"
\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",
" end | \n",
" start | \n",
" Color | \n",
" Part | \n",
" logo | \n",
" group | \n",
" label | \n",
" cvalue | \n",
"
\n",
" \n",
" id | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 🔱 PRM - Partidul România Mare | \n",
" 2008-12-13 | \n",
" 1992-10-21 | \n",
" PRM | \n",
" 🔱 PRM | \n",
" 🔱 | \n",
" PRM | \n",
" 🔱 PRM | \n",
" #0d5ca4 | \n",
"
\n",
" \n",
" ✳️ PNTCD - Partidul Naţional Ţărănesc Creştin Democrat | \n",
" 2014-03-01 | \n",
" 1990-06-18 | \n",
" PNTCD | \n",
" ✳️ PNTCD | \n",
" ✳️ | \n",
" PNTCD | \n",
" ✳️ PNTCD | \n",
" #04843c | \n",
"
\n",
" \n",
" 📐 PAC - Partidul Alianţei Civice | \n",
" 1996-11-22 | \n",
" 1992-10-21 | \n",
" PAC | \n",
" 📐 PAC | \n",
" 📐 | \n",
" PNL | \n",
" 📐 PNL | \n",
" #f4d42c | \n",
"
\n",
" \n",
" 📐 PNL - Partidul Naţional Liberal | \n",
" 2019-07-01 | \n",
" 1990-06-18 | \n",
" PNL | \n",
" 📐 PNL | \n",
" 📐 | \n",
" PNL | \n",
" 📐 PNL | \n",
" #f4d42c | \n",
"
\n",
" \n",
" 🔶 PDL - Partidul Democrat Liberal | \n",
" 2015-02-01 | \n",
" 2004-12-17 | \n",
" PDL | \n",
" 🔶 PDL | \n",
" 🔶 | \n",
" PD | \n",
" 🔶 PD | \n",
" darkOrange | \n",
"
\n",
" \n",
" ⚪️ FSN - Frontul Salvării Naţionale | \n",
" 1994-05-23 | \n",
" 1990-06-18 | \n",
" FSN | \n",
" ⚪️ FSN | \n",
" ⚪️ | \n",
" FSN | \n",
" ⚪️ FSN | \n",
" grey | \n",
"
\n",
" \n",
" 🔶 PD - Partidul Democrat | \n",
" 2008-12-13 | \n",
" 1992-10-26 | \n",
" PD | \n",
" 🔶 PD | \n",
" 🔶 | \n",
" PD | \n",
" 🔶 PD | \n",
" darkOrange | \n",
"
\n",
" \n",
" 🌹 PSM - Partidul Socialist al Muncii | \n",
" 1996-11-22 | \n",
" 1992-10-21 | \n",
" PSM | \n",
" 🌹 PSM | \n",
" 🌹 | \n",
" PSD | \n",
" 🌹 PSD | \n",
" #dc2c24 | \n",
"
\n",
" \n",
" 🌷 RMDSZ - Romániai Magyar Demokrata Szövetség | \n",
" 2019-07-01 | \n",
" 1990-06-18 | \n",
" RMDSZ | \n",
" 🌷 RMDSZ | \n",
" 🌷 | \n",
" RMDSZ | \n",
" 🌷 RMDSZ | \n",
" green | \n",
"
\n",
" \n",
" 🌹 PSD - Partidul Social Democrat | \n",
" 2019-07-01 | \n",
" 2000-12-15 | \n",
" PSD | \n",
" 🌹 PSD | \n",
" 🌹 | \n",
" PSD | \n",
" 🌹 PSD | \n",
" #dc2c24 | \n",
"
\n",
" \n",
" 👤 Independent - Independent | \n",
" 2019-07-01 | \n",
" 1990-06-18 | \n",
" Independent | \n",
" 👤 Independent | \n",
" 👤 | \n",
" Independent | \n",
" 👤 Independent | \n",
" #555 | \n",
"
\n",
" \n",
" 🕊️ ALDE - Partidul Alianţa Liberalilor şi Democraţilor | \n",
" 2019-07-01 | \n",
" 2016-12-21 | \n",
" ALDE | \n",
" 🕊️ ALDE | \n",
" 🕊️ | \n",
" ALDE | \n",
" 🕊️ ALDE | \n",
" #046cab | \n",
"
\n",
" \n",
" 🌹 PDSR - Partidul Democraţiei Sociale din România | \n",
" 2001-06-01 | \n",
" 1992-10-26 | \n",
" PDSR | \n",
" 🌹 PDSR | \n",
" 🌹 | \n",
" PSD | \n",
" 🌹 PSD | \n",
" #dc2c24 | \n",
"
\n",
" \n",
" 🔷 USR - Uniunea Salvaţi România | \n",
" 2019-07-01 | \n",
" 2016-12-21 | \n",
" USR | \n",
" 🔷 USR | \n",
" 🔷 | \n",
" USR | \n",
" 🔷 USR | \n",
" #04abe4 | \n",
"
\n",
" \n",
" 🕊️ PUR-SL - Partidul Umanist din România | \n",
" 2005-05-01 | \n",
" 2000-12-15 | \n",
" PUR-SL | \n",
" 🕊️ PUR | \n",
" 🕊️ | \n",
" ALDE | \n",
" 🕊️ ALDE | \n",
" #046cab | \n",
"
\n",
" \n",
" ⚛️ PP-DD - Partidul Poporului Dan Diaconescu | \n",
" 2015-08-01 | \n",
" 2012-12-20 | \n",
" PP-DD | \n",
" ⚛️ PP | \n",
" ⚛️ | \n",
" PP-DD | \n",
" ⚛️ PP-DD | \n",
" #9966cc | \n",
"
\n",
" \n",
" 🦅 UNPR - Uniunea Naţională pentru Progresul României | \n",
" 2016-12-21 | \n",
" 2012-12-20 | \n",
" UNPR | \n",
" 🦅 UNPR | \n",
" 🦅 | \n",
" UNPR | \n",
" 🦅 UNPR | \n",
" #a8190f | \n",
"
\n",
" \n",
" 📐 PNL-CD - Partidul Naţional Liberal | \n",
" 2000-11-30 | \n",
" 1992-10-21 | \n",
" PNL-CD | \n",
" 📐 PNL | \n",
" 📐 | \n",
" PNL | \n",
" 📐 PNL | \n",
" #f4d42c | \n",
"
\n",
" \n",
" 🕊️ PC - Partidul Conservator | \n",
" 2016-12-21 | \n",
" 2004-12-17 | \n",
" PC | \n",
" 🕊️ PC | \n",
" 🕊️ | \n",
" ALDE | \n",
" 🕊️ ALDE | \n",
" #046cab | \n",
"
\n",
" \n",
" 🕊️ PUNR - Partidul Unităţii Naţionale Române | \n",
" 2000-11-30 | \n",
" 1990-06-18 | \n",
" PUNR | \n",
" 🕊️ PUNR | \n",
" 🕊️ | \n",
" ALDE | \n",
" 🕊️ ALDE | \n",
" #046cab | \n",
"
\n",
" \n",
" 📐 PL'93 - Partidul Liberal | \n",
" 1996-11-22 | \n",
" 1992-10-28 | \n",
" PL'93 | \n",
" 📐 PL'93 | \n",
" 📐 | \n",
" PNL | \n",
" 📐 PNL | \n",
" #f4d42c | \n",
"
\n",
" \n",
" ⚪️ FDSN - Frontul Democrat al Salvarii Nationale | \n",
" 1993-07-01 | \n",
" 1990-06-18 | \n",
" FDSN | \n",
" ⚪️ FDSN | \n",
" ⚪️ | \n",
" FSN | \n",
" ⚪️ FSN | \n",
" grey | \n",
"
\n",
" \n",
" 🍏 PMP - Partidul Mişcarea Populară | \n",
" 2019-07-01 | \n",
" 2016-12-21 | \n",
" PMP | \n",
" 🍏 PMP | \n",
" 🍏 | \n",
" PMP | \n",
" 🍏 PMP | \n",
" #0484cc | \n",
"
\n",
" \n",
" 🔘 PTLDR - Partidul Tineretului Liber Democrat din România | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" PTLDR | \n",
" 🔘 PTLDR | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🔘 PLS - Partidul Liber Schimbist | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" PLS | \n",
" 🔘 PLS | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🌹 PSDR - Partidul Socialist Democratic din România | \n",
" 2001-06-01 | \n",
" 1990-06-18 | \n",
" PSDR | \n",
" 🌹 PSDR | \n",
" 🌹 | \n",
" PSD | \n",
" 🌹 PSD | \n",
" #dc2c24 | \n",
"
\n",
" \n",
" 🍀 PER - Partidul Ecologist Român | \n",
" 2000-11-30 | \n",
" 1990-06-18 | \n",
" PER | \n",
" 🍀 PER | \n",
" 🍀 | \n",
" ECO | \n",
" 🍀 ECO | \n",
" #69a54f | \n",
"
\n",
" \n",
" 🔘 PAR - Partidul Alternativa României | \n",
" 2000-11-30 | \n",
" 1996-11-27 | \n",
" PAR | \n",
" 🔘 PAR | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🔘 FC - Forţa Civică | \n",
" 2015-07-01 | \n",
" 2012-12-20 | \n",
" FC | \n",
" 🔘 FC | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🍀 PDAR - Partidul Democrat Agrar din România | \n",
" 1996-11-22 | \n",
" 1990-06-18 | \n",
" PDAR | \n",
" 🍀 PDAR | \n",
" 🍀 | \n",
" ECO | \n",
" 🍀 ECO | \n",
" #69a54f | \n",
"
\n",
" \n",
" 🔘 PRNR - Partidul Reconstrucţiei Naţionale din România | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" PRNR | \n",
" 🔘 PRNR | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🍀 MER - Mişcarea Ecologistă din România | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" MER | \n",
" 🍀 MER | \n",
" 🍀 | \n",
" ECO | \n",
" 🍀 ECO | \n",
" #69a54f | \n",
"
\n",
" \n",
" 📐 PNL-AT - Partidul Naţional Liberal | \n",
" 1993-02-25 | \n",
" 1992-10-21 | \n",
" PNL-AT | \n",
" 📐 PNL | \n",
" 📐 | \n",
" PNL | \n",
" 📐 PNL | \n",
" #f4d42c | \n",
"
\n",
" \n",
" 🍀 FER - Federaţia Ecologistă Română | \n",
" 2000-11-30 | \n",
" 1996-11-27 | \n",
" FER | \n",
" 🍀 FER | \n",
" 🍀 | \n",
" ECO | \n",
" 🍀 ECO | \n",
" #69a54f | \n",
"
\n",
" \n",
" 🔘 GDC - Gruparea Democratică de Centru | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" GDC | \n",
" 🔘 GDC | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🔘 AUR - Alianţa pentru Unitatea Românilor | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" AUR | \n",
" 🔘 AUR | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🔘 PDM - Partidul Democrat al Muncii | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" PDM | \n",
" 🔘 PDM | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 🔘 ULB - Uniunea Liberală \"Brătianu\" | \n",
" 1992-10-16 | \n",
" 1990-06-18 | \n",
" ULB | \n",
" 🔘 ULB | \n",
" 🔘 | \n",
" Mas | \n",
" 🔘 Mas | \n",
" #777 | \n",
"
\n",
" \n",
" 👤 Minorități - Minorități | \n",
" 2019-07-01 | \n",
" 2016-12-21 | \n",
" Minorități | \n",
" 👤 Minorități | \n",
" 👤 | \n",
" Independent | \n",
" 👤 Independent | \n",
" #555 | \n",
"
\n",
" \n",
"
\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
}