import numpy as np
import random
liste = ['Max', 'Andi', 'Simon', 'Robin', 'Rosina']
np.random.shuffle(liste)
liste
['Rosina', 'Andi', 'Max', 'Robin', 'Simon']
import pandas as pd
data = pd.read_csv("all_votes.tsv", sep = "\t")
import matplotlib.pyplot as plt
data.head()
| id | poll_id | mandate_label | poll_label | vote | reason_no_show | fraction_label | poll_date | |
|---|---|---|---|---|---|---|---|---|
| 0 | 420205 | 4293 | Frauke Petry (Bundestag 2017 - 2021) | Änderung des Infektionsschutzgesetzes und Grun... | no | NaN | fraktionslos (Bundestag 2017 - 2021) | 2021-09-07 |
| 1 | 420204 | 4293 | Frank Pasemann (Bundestag 2017 - 2021) | Änderung des Infektionsschutzgesetzes und Grun... | no | NaN | fraktionslos (Bundestag 2017 - 2021) | 2021-09-07 |
| 2 | 420203 | 4293 | Georg Nüßlein (Bundestag 2017 - 2021) | Änderung des Infektionsschutzgesetzes und Grun... | yes | NaN | fraktionslos (Bundestag 2017 - 2021) | 2021-09-07 |
| 3 | 420202 | 4293 | Mario Mieruch (Bundestag 2017 - 2021) | Änderung des Infektionsschutzgesetzes und Grun... | no | NaN | fraktionslos (Bundestag 2017 - 2021) | 2021-09-07 |
| 4 | 420201 | 4293 | Uwe Kamann (Bundestag 2017 - 2021) | Änderung des Infektionsschutzgesetzes und Grun... | no_show | NaN | fraktionslos (Bundestag 2017 - 2021) | 2021-09-07 |
plt.hist(data.vote)
(array([48647., 0., 0., 58135., 0., 0., 13042., 0.,
0., 4738.]),
array([0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4, 2.7, 3. ]),
<BarContainer object of 10 artists>)
data_gr = data.groupby(["mandate_label", "vote"]).size()
print(data_gr)
mandate_label vote
Achim Kessler (Bundestag 2017 - 2021) abstain 17
no 99
no_show 19
yes 41
Achim Post (Bundestag 2017 - 2021) no 54
...
Zaklin Nastić (Bundestag 2017 - 2021) abstain 16
no 111
no_show 13
yes 36
Zeki Gökhan (Bundestag 2017 - 2021) no 3
Length: 2628, dtype: int64
data_gr[0:8].plot(kind = "bar")
<Axes: xlabel='mandate_label,vote'>
plt.hist(data_gr)
(array([646., 413., 215., 184., 403., 175., 113., 156., 312., 11.]), array([ 1., 14., 27., 40., 53., 66., 79., 92., 105., 118., 131.]), <BarContainer object of 10 artists>)
data_sorted = data.sort_values(by="vote")
data_sorted
| id | poll_id | mandate_label | poll_label | vote | reason_no_show | fraction_label | poll_date | |
|---|---|---|---|---|---|---|---|---|
| 61695 | 322105 | 1690 | Gökay Akbulut (Bundestag 2017 - 2021) | Betrieb von Kohlekraftwerken zur Stromerzeugun... | abstain | NaN | DIE LINKE (Bundestag 2017 - 2021) | 2019-06-28 |
| 17088 | 396621 | 4097 | Sven-Christian Kindler (Bundestag 2017 - 2021) | Verlängerung der Beteiligung der Bundeswehr an... | abstain | NaN | DIE GRÜNEN (Bundestag 2017 - 2021) | 2021-04-21 |
| 17089 | 396620 | 4097 | Katja Keul (Bundestag 2017 - 2021) | Verlängerung der Beteiligung der Bundeswehr an... | abstain | NaN | DIE GRÜNEN (Bundestag 2017 - 2021) | 2021-04-21 |
| 113543 | 98066 | 1285 | Cem Özdemir (Bundestag 2017 - 2021) | Verlängerung des Bundeswehreinsatzes im Mittel... | abstain | NaN | DIE GRÜNEN (Bundestag 2017 - 2021) | 2018-03-22 |
| 17090 | 396619 | 4097 | Uwe Kekeritz (Bundestag 2017 - 2021) | Verlängerung der Beteiligung der Bundeswehr an... | abstain | NaN | DIE GRÜNEN (Bundestag 2017 - 2021) | 2021-04-21 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 84079 | 297435 | 1636 | Carsten Brodesser (Bundestag 2017 - 2021) | Digitalpakt - Änderung des Grundgesetzes | yes | NaN | CDU/CSU (Bundestag 2017 - 2021) | 2019-02-21 |
| 84080 | 297434 | 1636 | Ralph Brinkhaus (Bundestag 2017 - 2021) | Digitalpakt - Änderung des Grundgesetzes | yes | NaN | CDU/CSU (Bundestag 2017 - 2021) | 2019-02-21 |
| 84081 | 297433 | 1636 | Leni Breymaier (Bundestag 2017 - 2021) | Digitalpakt - Änderung des Grundgesetzes | yes | NaN | SPD (Bundestag 2017 - 2021) | 2019-02-21 |
| 19166 | 390295 | 4093 | Michael von Abercron (Bundestag 2017 - 2021) | Energieversorgung in Deutschland | yes | NaN | CDU/CSU (Bundestag 2017 - 2021) | 2021-04-14 |
| 62280 | 321546 | 1688 | Sonja Steffen (Bundestag 2017 - 2021) | Verlängerung des Bundeswehreinsatzes im Kosovo... | yes | NaN | SPD (Bundestag 2017 - 2021) | 2019-06-28 |
124562 rows × 8 columns
abstain = data[data.vote == "abstain"]
no_show = data[data.vote == "no_show"]
yes = data[data.vote == "yes"]
no = data[data.vote == "no"]
abstain_gr = abstain.groupby("fraction_label").size()
abstain_gr.sort_values(ascending=False).plot(kind = "bar", title = "ABSTAIN")
<Axes: title={'center': 'ABSTAIN'}, xlabel='fraction_label'>
abstain_gr = abstain.groupby("mandate_label").size()
abstain_gr.sort_values(ascending=False)
mandate_label
Mario Mieruch (Bundestag 2017 - 2021) 34
Lisa Paus (Bundestag 2017 - 2021) 31
Margarete Bause (Bundestag 2017 - 2021) 30
Matthias Gastel (Bundestag 2017 - 2021) 30
Renate Künast (Bundestag 2017 - 2021) 29
..
Klaus-Peter Willsch (Bundestag 2017 - 2021) 1
Sepp Müller (Bundestag 2017 - 2021) 1
Saskia Ludwig (Bundestag 2017 - 2021) 1
Sascha Raabe (Bundestag 2017 - 2021) 1
Frank Steffel (Bundestag 2017 - 2021) 1
Length: 420, dtype: int64
no_show_gr = no_show.groupby("mandate_label").size()
no_show_gr.sort_values(ascending=False)
mandate_label
Angela Merkel (Bundestag 2017 - 2021) 131
Ingrid Remmers (Bundestag 2017 - 2021) 120
Helge Braun (Bundestag 2017 - 2021) 110
Sahra Wagenknecht (Bundestag 2017 - 2021) 109
Marcus Held (Bundestag 2017 - 2021) 109
...
Dietrich Monstadt (Bundestag 2017 - 2021) 1
Hermann Gröhe (Bundestag 2017 - 2021) 1
Markus Koob (Bundestag 2017 - 2021) 1
Fabian Jacobi (Bundestag 2017 - 2021) 1
Hansjörg Durz (Bundestag 2017 - 2021) 1
Length: 716, dtype: int64
no_show_gr = no_show.groupby("fraction_label").size()
no_show_gr.sort_values(ascending=False).plot(kind = "bar", title = "NO_SHOW")
<Axes: title={'center': 'NO_SHOW'}, xlabel='fraction_label'>
no_gr = no.groupby("mandate_label").size()
no_gr.sort_values(ascending=False)
mandate_label
Rainer Kraft (Bundestag 2017 - 2021) 124
Wolfgang Wiehle (Bundestag 2017 - 2021) 122
Karsten Hilse (Bundestag 2017 - 2021) 122
Michael Espendiller (Bundestag 2017 - 2021) 121
Marcus Bühl (Bundestag 2017 - 2021) 120
...
Tobias Zech (Bundestag 2017 - 2021) 6
Thomas Viesehon (Bundestag 2017 - 2021) 3
Zeki Gökhan (Bundestag 2017 - 2021) 3
Florian Jäger (Bundestag 2017 - 2021) 2
Jimmy Schulz (Bundestag 2017 - 2021) 2
Length: 746, dtype: int64
no_gr = no.groupby("fraction_label").size()
no_gr.sort_values(ascending=False).plot(kind = "bar", title = "NO")
<Axes: title={'center': 'NO'}, xlabel='fraction_label'>
yes_gr = yes.groupby("fraction_label").size()
yes_gr.sort_values(ascending=False).plot(kind = "bar", title = "YES")
<Axes: title={'center': 'YES'}, xlabel='fraction_label'>
data_gr[0:4].plot(kind = "bar")
<Axes: xlabel='vote,mandate_label'>