names = ['Laura', 'David', 'Markus']
import numpy as np
import pandas as pd
np.random.choice(names)
'David'
np.random.choice(names)
'Laura'
unvotes = pd.read_csv("unvotes.csv", index_col=0)
unvotes
| country | country_code | vote | |
|---|---|---|---|
| rcid | |||
| 3 | United States | US | yes |
| 3 | Canada | CA | no |
| 3 | Cuba | CU | yes |
| 3 | Haiti | HT | yes |
| 3 | Dominican Republic | DO | yes |
| ... | ... | ... | ... |
| 9101 | Venezuela | VE | yes |
| 9101 | Vietnam | VN | yes |
| 9101 | Yemen | YE | yes |
| 9101 | Zambia | ZM | yes |
| 9101 | Zimbabwe | ZW | yes |
869937 rows × 3 columns
roll_calls = pd.read_csv("roll_calls.csv", index_col=0)
roll_calls
| session | importantvote | date | unres | amend | para | short | descr | |
|---|---|---|---|---|---|---|---|---|
| rcid | ||||||||
| 3 | 1 | 0.0 | 1946-01-01 | R/1/66 | 1.0 | 0.0 | AMENDMENTS, RULES OF PROCEDURE | TO ADOPT A CUBAN AMENDMENT TO THE UK PROPOSAL ... |
| 4 | 1 | 0.0 | 1946-01-02 | R/1/79 | 0.0 | 0.0 | SECURITY COUNCIL ELECTIONS | TO ADOPT A USSR PROPOSAL ADJOURNING DEBATE ON ... |
| 5 | 1 | 0.0 | 1946-01-04 | R/1/98 | 0.0 | 0.0 | VOTING PROCEDURE | TO ADOPT THE KOREAN PROPOSAL THAT INVALID BALL... |
| 6 | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... |
| 7 | 1 | 0.0 | 1946-01-02 | R/1/295 | 1.0 | 0.0 | GENERAL ASSEMBLY ELECTIONS | TO ADOPT A 6TH COMMITTEE AMENDMENT (A/14) TO T... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 9143 | 74 | NaN | 2019-12-12 | A/RES/74/56 | NaN | NaN | Convening of the 4th special session of the Ge... | Convening of the 4th special session of the Ge... |
| 9144 | 74 | NaN | 2019-12-27 | A/RES/74/251 | NaN | NaN | Programme planning | Programme planning |
| 9145 | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... |
| 9146 | 74 | NaN | 2019-12-19 | A/RES/74/208 | NaN | NaN | Oil slick on Lebanese shores | Oil slick on Lebanese shores |
| 9147 | 74 | NaN | 2019-12-10 | A/RES/74/19 | NaN | NaN | Oceans and the law of the sea | Oceans and the law of the sea |
6202 rows × 8 columns
issues = pd.read_csv("issues.csv", index_col=0)
issues
| short_name | issue | |
|---|---|---|
| rcid | ||
| 77 | me | Palestinian conflict |
| 9001 | me | Palestinian conflict |
| 9002 | me | Palestinian conflict |
| 9003 | me | Palestinian conflict |
| 9004 | me | Palestinian conflict |
| ... | ... | ... |
| 9145 | ec | Economic development |
| 9069 | ec | Economic development |
| 9074 | ec | Economic development |
| 9095 | ec | Economic development |
| 9092 | ec | Economic development |
5745 rows × 2 columns
set(roll_calls.index) == set(issues.index)
False
set([1,2]) == set([1,2])
True
len(set(roll_calls.index) - set(issues.index))
2103
set(issues.index) - set(roll_calls.index)
set()
len(set(roll_calls.index))
6202
issues_with_rcs = pd.merge(roll_calls, issues, left_index=True, right_index=True)
issues_with_rcs
| session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|
| rcid | ||||||||||
| 6 | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| 8 | 1 | 0.0 | 1946-01-05 | R/1/297 | 1.0 | 0.0 | ECOSOC POWERS | TO ADOPT A SECOND 6TH COMM. AMENDMENT (A/14) T... | ec | Economic development |
| 11 | 1 | 0.0 | 1946-02-05 | R/1/376 | 0.0 | 0.0 | TRUSTEESHIP AMENDMENTS | TO ADOPT DRAFT RESOLUTIONS I AND II AS A WHOLE... | co | Colonialism |
| 11 | 1 | 0.0 | 1946-02-05 | R/1/376 | 0.0 | 0.0 | TRUSTEESHIP AMENDMENTS | TO ADOPT DRAFT RESOLUTIONS I AND II AS A WHOLE... | ec | Economic development |
| 18 | 1 | 0.0 | 1946-02-03 | R/1/532 | 1.0 | 0.0 | ECOSOC CONSULTANTS | TO ADOPT USSR (ORAL) AMENDMENT REPLACING THE 1... | ec | Economic development |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 9142 | 74 | NaN | 2019-12-12 | A/RES/74/33 | NaN | NaN | No first placement of weapons in outer space | No first placement of weapons in outer space | co | Colonialism |
| 9142 | 74 | NaN | 2019-12-12 | A/RES/74/33 | NaN | NaN | No first placement of weapons in outer space | No first placement of weapons in outer space | ec | Economic development |
| 9145 | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | di | Arms control and disarmament |
| 9145 | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | ec | Economic development |
5745 rows × 10 columns
issues_with_rcs[issues_with_rcs.index == 9145]['descr'].iloc[0]
'Conventional arms control at the regional and subregional levels '
full_dataset = pd.merge(unvotes, issues_with_rcs, left_index = True, right_index = True)
full_dataset
| country | country_code | vote | session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rcid | |||||||||||||
| 6 | United States | US | no | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| 6 | Canada | CA | no | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| 6 | Cuba | CU | yes | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| 6 | Dominican Republic | DO | abstain | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| 6 | Mexico | MX | yes | 1 | 0.0 | 1946-01-04 | R/1/107 | 0.0 | 0.0 | DECLARATION OF HUMAN RIGHTS | TO ADOPT A CUBAN PROPOSAL (A/3-C) THAT AN ITEM... | hr | Human rights |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 9145 | Zambia | ZM | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Zambia | ZM | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | ec | Economic development |
| 9145 | Zimbabwe | ZW | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | di | Arms control and disarmament |
| 9145 | Zimbabwe | ZW | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Zimbabwe | ZW | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | ec | Economic development |
857878 rows × 13 columns
tmp = full_dataset[(full_dataset.index == 9145) & (full_dataset.issue == 'Colonialism')]
tmp
| country | country_code | vote | session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rcid | |||||||||||||
| 9145 | Afghanistan | AF | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Albania | AL | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Algeria | DZ | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Andorra | AD | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Angola | AO | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 9145 | Venezuela | VE | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Vietnam | VN | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Yemen | YE | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Zambia | ZM | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Zimbabwe | ZW | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
188 rows × 13 columns
df = tmp.groupby(["vote"]).count()
df
| country | country_code | session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| vote | ||||||||||||
| abstain | 2 | 2 | 2 | 0 | 2 | 2 | 0 | 0 | 2 | 2 | 2 | 2 |
| no | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
| yes | 185 | 184 | 185 | 0 | 185 | 185 | 0 | 0 | 185 | 185 | 185 | 185 |
tmp[tmp.vote!="yes"]
| country | country_code | vote | session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rcid | |||||||||||||
| 9145 | Bhutan | BT | abstain | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | India | IN | no | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
| 9145 | Russia | RU | abstain | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
tmp[tmp.country_code.isna()]
| country | country_code | vote | session | importantvote | date | unres | amend | para | short | descr | short_name | issue | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rcid | |||||||||||||
| 9145 | Namibia | NaN | yes | 74 | NaN | 2019-12-12 | A/RES/74/38 | NaN | NaN | Conventional arms control at the regional and ... | Conventional arms control at the regional and ... | co | Colonialism |
unvotes[unvotes.country =="Namibia"]
| country | country_code | vote | |
|---|---|---|---|
| rcid | |||
| 3501 | Namibia | NaN | yes |
| 3503 | Namibia | NaN | yes |
| 3504 | Namibia | NaN | yes |
| 3505 | Namibia | NaN | yes |
| 3506 | Namibia | NaN | yes |
| ... | ... | ... | ... |
| 9092 | Namibia | NaN | yes |
| 9097 | Namibia | NaN | yes |
| 9100 | Namibia | NaN | yes |
| 9098 | Namibia | NaN | yes |
| 9101 | Namibia | NaN | yes |
2454 rows × 3 columns
np.unique(unvotes[unvotes.country_code.isna()].country)
array(['Federal Republic of Germany', 'Namibia', 'Yemen Arab Republic',
'Zanzibar'], dtype=object)
unvotes
| country | country_code | vote | |
|---|---|---|---|
| rcid | |||
| 3 | United States | US | yes |
| 3 | Canada | CA | no |
| 3 | Cuba | CU | yes |
| 3 | Haiti | HT | yes |
| 3 | Dominican Republic | DO | yes |
| ... | ... | ... | ... |
| 9101 | Venezuela | VE | yes |
| 9101 | Vietnam | VN | yes |
| 9101 | Yemen | YE | yes |
| 9101 | Zambia | ZM | yes |
| 9101 | Zimbabwe | ZW | yes |
869937 rows × 3 columns
countries = set(unvotes.country)
from itertools import combinations
list(combinations([1,2,3],2))
[(1, 2), (1, 3), (2, 3)]
country_1 = 'United States'
country_2 = 'Russia'
dtemp = [votes for votes in unvotes.groupby('country') if votes[0] in ('United States', 'Russia')]
votes_russia = dtemp[0]
votes_us = dtemp[1]
russia_nos = votes_russia[1][votes_russia[1].vote == "no"]
russia_nos
| country | country_code | vote | |
|---|---|---|---|
| rcid | |||
| 3 | Russia | RU | no |
| 6 | Russia | RU | no |
| 7 | Russia | RU | no |
| 12 | Russia | RU | no |
| 16 | Russia | RU | no |
| ... | ... | ... | ... |
| 9077 | Russia | RU | no |
| 9069 | Russia | RU | no |
| 9076 | Russia | RU | no |
| 9075 | Russia | RU | no |
| 9095 | Russia | RU | no |
906 rows × 3 columns
len(set(russia_nos.index))
906
votes_russia_us = pd.merge(votes_russia[1], votes_us[1], left_index=True, right_index=True)
votes_russia_us
| country_x | country_code_x | vote_x | country_y | country_code_y | vote_y | |
|---|---|---|---|---|---|---|
| rcid | ||||||
| 3 | Russia | RU | no | United States | US | yes |
| 4 | Russia | RU | yes | United States | US | no |
| 5 | Russia | RU | yes | United States | US | no |
| 6 | Russia | RU | no | United States | US | no |
| 7 | Russia | RU | no | United States | US | no |
| ... | ... | ... | ... | ... | ... | ... |
| 9095 | Russia | RU | no | United States | US | no |
| 9092 | Russia | RU | yes | United States | US | no |
| 9100 | Russia | RU | yes | United States | US | no |
| 9098 | Russia | RU | yes | United States | US | no |
| 9101 | Russia | RU | abstain | United States | US | no |
6118 rows × 6 columns
votes_russia_us[votes_russia_us.vote_x != votes_russia_us.vote_y]
| country_x | country_code_x | vote_x | country_y | country_code_y | vote_y | |
|---|---|---|---|---|---|---|
| rcid | ||||||
| 3 | Russia | RU | no | United States | US | yes |
| 4 | Russia | RU | yes | United States | US | no |
| 5 | Russia | RU | yes | United States | US | no |
| 8 | Russia | RU | yes | United States | US | no |
| 12 | Russia | RU | no | United States | US | yes |
| ... | ... | ... | ... | ... | ... | ... |
| 9086 | Russia | RU | yes | United States | US | no |
| 9092 | Russia | RU | yes | United States | US | no |
| 9100 | Russia | RU | yes | United States | US | no |
| 9098 | Russia | RU | yes | United States | US | no |
| 9101 | Russia | RU | abstain | United States | US | no |
4776 rows × 6 columns
from tqdm.notebook import tqdm
disagreement = {}
for country_1, country_2 in tqdm(list(combinations(countries, 2))):
dtemp = [votes for votes in unvotes.groupby('country') if votes[0] in (country_1, country_2)]
votes_russia = dtemp[0]
votes_us = dtemp[1]
votes_russia_us = pd.merge(votes_russia[1], votes_us[1], left_index=True, right_index=True)
if votes_russia_us.shape[0] == 0:
continue
df = votes_russia_us[votes_russia_us.vote_x != votes_russia_us.vote_y]
disagreement[country_1 + " -vs- " + country_2] = df.shape[0], df.shape[0]/votes_russia_us.shape[0]
max(disagreement, key=disagreement.get)
'Belarus -vs- United States'
disagreement[max(disagreement, key=disagreement.get)]
(4928, 0.8169761273209549)
max(disagreement, key=lambda x: disagreement.get(x)[1])
'Russia -vs- Zanzibar'
disagreement[max(disagreement, key=lambda x: disagreement.get(x)[1])]
(2, 1.0)