import pandas as pd # Load the data, selecting only the needed columns
un_roll_call_issues = pd.read_csv('un_roll_call_issues.csv', usecols=['rcid', 'issue'])
un_roll_calls = pd.read_csv('un_roll_calls.csv', usecols=['rcid', 'session', 'date'])
un_votes = pd.read_csv('un_votes.csv', usecols=['rcid', 'country', 'vote'])
# Merge the dataframes into a single chain
# First, un_roll_call_issues with un_roll_calls
# Then merge the result with un_votes
UN = un_roll_call_issues.merge(un_roll_calls, on='rcid') \
.merge(un_votes, on='rcid')
g20_members =[
"Argentina", "Australia", "Brazil", "Canada", "China",
"France", "Germany", "India", "Indonesia", "Italy",
"Japan", "Mexico", "Russia", "Saudi Arabia", "South Africa",
"South Korea", "Turkey", "United Kingdom", "United States"
]
G20 = UN.query("country in @g20_members") G20.groupby('issue').agg({'rcid':'nunique'}).reset_index() G20.groupby('issue').agg({'rcid':'nunique'}).reset_index().plot()
G20.groupby('issue').agg({'rcid':'nunique'}).reset_index().plot(
x='issue',
rot=45, figsize=(10,5)
)
G20.groupby('issue').agg({'rcid':'nunique'}).reset_index().plot(
x='issue',
rot=45, figsize=(10,5),
xlabel='Broad issue area',
ylabel='Number of roll calls',
legend=False
)
G20.groupby('issue').agg({'rcid':'nunique'}).reset_index().plot(
x='issue',
rot=45, figsize=(10,5),
xlabel='Broad issue area',
ylabel='Number of roll calls',
legend=False,
ylim=(0,1100)
)
G20.groupby('issue').agg({'rcid':'nunique'}).reset_index().plot(
x='issue',
rot=45, figsize=(10,5),
xlabel='Broad issue area',
ylabel='Number of roll calls',
legend=False, kind='bar'
)
# Import matplotlib
import matplotlib.pyplot as plt
# Filter the data and store it in a new variable
G20_abstain = G20.query('vote == "abstain"')
# Count abstentions by country
abstain_counts = G20_abstain['country'].value_counts()
# Create a pie chart
plt.figure(figsize=(10, 8))
plt.pie(
abstain_counts,
labels=abstain_counts.index,
autopct='%1.1f%%',
startangle=140
)
plt.title('Share of countries by number of abstentions', pad=20)
# Keep the pie circular
plt.axis('equal')
# Show the chart
plt.show()
import seaborn as sns G20_abstain['date'] = pd.to_datetime(G20_abstain['date'])
G20_abstain['year'] = G20_abstain['date'].dt.year # Filter for the country of interest
Russia_abstain = G20_abstain.query('country = "Russia"')
# Group by year and agenda; count votes
votes_by_year_issue = Russia_abstain.groupby(['year', 'issue']).size()\
.reset_index(name='count') # Scatterplot
plt.figure(figsize=(12, 8))
sns.scatterplot(
data=votes_by_year_issue,
x='year', y='count',
hue='issue',
palette='viridis',
s=100
)
# Formatting
plt.xlabel('Year', fontsize=14)
plt.ylabel('Number of votes', fontsize=14)
plt.legend(title='Agenda', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.grid(True, linestyle='--', alpha=0.7)
plt.tight_layout()
# Show the scatterplot
plt.show()