import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
UN Votes
Introduction
How do various countries vote in the United Nations General Assembly, how have their voting patterns evolved throughout time, and how similarly or differently do they view certain issues? Answering these questions (at a high level) is the focus of this analysis.
Packages
We will use the pandas, matplotlib, and seaborn packages for data wrangling and visualization.
Data
The data we’re using originally come from the unvotes R package. In the chunk below we modify the data by joining the various data frames provided in the package to help you get started with the analysis.
= pd.read_csv('data/un_votes.csv')
un_votes = pd.read_csv('data/un_roll_calls.csv')
un_roll_calls = pd.read_csv('data/un_roll_call_issues.csv')
un_roll_call_issues
= un_votes.merge(un_roll_calls, on='rcid').merge(un_roll_call_issues, on='rcid') unvotes
UN voting patterns
Let’s create a data visualization that displays how the voting record of the UK & NI changed over time on a variety of issues and compares it to two other countries: US and Turkey.
We can easily change which countries are being plotted by changing which countries the code filters for. Note that the country name should be spelled and capitalized exactly the same way as it appears in the data. See the Appendix for a list of the countries in the data.
# Filter the data for the selected countries and prepare for plotting
= unvotes[unvotes['country'].isin(['United Kingdom', 'United States', 'Turkey'])]
filtered_unvotes 'year'] = pd.to_datetime(filtered_unvotes['date']).dt.year
filtered_unvotes[
# Calculate the percentage of 'yes' votes per year, per country, per issue
= filtered_unvotes.groupby(['country', 'year', 'issue'])['vote'].apply(lambda x: (x == 'yes').mean()).reset_index()
percent_yes ={'vote': 'percent_yes'}, inplace=True)
percent_yes.rename(columns
# Create the faceted plot
= sns.FacetGrid(percent_yes, col="issue", hue="country", col_wrap=3)
g map(sns.scatterplot, "year", "percent_yes", alpha=0.4)
g.map(sns.regplot, "year", "percent_yes", lowess=True, scatter=False)
g.
# Adjust the labels and titles
"Year", "% Yes")
g.set_axis_labels(="{col_name}")
g.set_titles(col_template="Country")
g.add_legend(title"Percentage of 'Yes' votes in the UN General Assembly", y=1.02)
g.fig.suptitle(=0.9)
plt.subplots_adjust(top
plt.show()
References
- David Robinson (2017). unvotes: United Nations General Assembly Voting Data. R package version 0.2.0.
- Erik Voeten “Data and Analyses of Voting in the UN General Assembly” Routledge Handbook of International Organization, edited by Bob Reinalda (published May 27, 2013).
- Much of the analysis has been modeled on the examples presented in the unvotes R package vignette.
Appendix
Below is a list of countries in the dataset:
country | |
---|---|
0 | Afghanistan |
1 | Albania |
2 | Algeria |
3 | Andorra |
4 | Angola |
... | ... |
195 | Yemen People's Republic |
196 | Yugoslavia |
197 | Zambia |
198 | Zanzibar |
199 | Zimbabwe |
200 rows × 1 columns