The Nobel Prize has been among the most prestigious international awards since 1901. Each year, awards are bestowed in chemistry, literature, physics, physiology or medicine, economics, and peace. In addition to the honor, prestige, and substantial prize money, the recipient also gets a gold medal with an image of Alfred Nobel (1833 - 1896), who established the prize.
The Nobel Foundation has made a dataset available of all prize winners from the outset of the awards from 1901 to 2023. The dataset used in this project is from the Nobel Prize API and is available in the nobel.csv file in the data folder.
In this project, you'll get a chance to explore and answer several questions related to this prizewinning data. And we encourage you then to explore further questions that you're interested in!
# Loading in required libraries
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt # Added this line to import matplotlib.pyplot
# Start coding here!
# Read in the Nobel Prize data
nobel_df = pd.read_csv('data/nobel.csv')
top_gender = nobel_df['sex'].value_counts().idxmax()
top_country = nobel_df['birth_country'].value_counts().idxmax()
top_gender = nobel_df['sex'].value_counts().index[0]
top_country = nobel_df['birth_country'].value_counts().index[0]
print(top_gender)
print(top_country)
#Create the US-born winners column
nobel_df['usa_born_winner'] = nobel_df['birth_country'] =='United States of America'
nobel_df['decade']= (nobel_df['year'] // 10) * 10
total_by_decade = nobel_df.groupby('decade').size()
us_by_decade = nobel_df[nobel_df['birth_country'] == 'United States of America'].groupby('decade').size()
us_ratio = (us_by_decade / total_by_decade).fillna(0)
max_decade_usa = int(us_ratio.idxmax())
print(max_decade_usa)
# Create the prop_usa_winners DataFrame
prop_usa_winners = us_ratio.reset_index(name='usa_born_winner')
ax1 = sns.relplot(x='decade', y='usa_born_winner', data=prop_usa_winners, kind="line")
# Calculating the proportion of female laureates per decade
nobel_df['female_winner'] = nobel_df['sex'] == 'Female'
prop_female_winners = nobel_df.groupby(['decade', 'category'], as_index=False)['female_winner'].mean()
# Find the decade and category with the highest proportion of female laureates
max_female_decade_category = prop_female_winners[prop_female_winners['female_winner'] == prop_female_winners['female_winner'].max()][['decade', 'category']]
# Create a dictionary with the decade and category pair
max_female_dict = {max_female_decade_category['decade'].values[0]: max_female_decade_category['category'].values[0]}
# Optional: Plotting female winners with % winners on the y-axis
ax2 = sns.relplot(x='decade', y='female_winner', hue='category', data=prop_female_winners, kind="line")
# Finding the first woman to win a Nobel Prize
nobel_women = nobel_df[nobel_df['sex'] == 'Female']
if not nobel_women.empty:
min_row = nobel_women[nobel_women['year'] == nobel_women['year'].min()]
first_woman_name = min_row['full_name'].values[0]
first_woman_category = min_row['category'].values[0]
print(f"\n The first woman to win a Nobel Prize was {first_woman_name}, in the category of {first_woman_category}.")
else:
print("\n No female Nobel Prize winners found in the dataset.")
# Count how many times each fullName appears
name_counts = nobel_df['full_name'].value_counts()
# Filter for names that appear more than once
repeat_list = name_counts[name_counts > 1].index.tolist()
# Print the result
print("Repeat winners:", repeat_list)
print(max_female_dict)
# Female laureates per decade
female_by_decade = nobel_df[nobel_df['sex'] == 'Female'].groupby('decade').size()
total_by_decade = nobel_df.groupby('decade').size()
female_ratio = (female_by_decade / total_by_decade).fillna(0)
# Plot
plt.figure(figsize=(10, 5))
sns.lineplot(x=female_ratio.index, y=female_ratio.values)
plt.title("Proportion of Female Nobel Laureates by Decade")
plt.xlabel("Decade")
plt.ylabel("Female Proportion")
plt.grid(True)
plt.show()
# Top 10 countries by number of winners
top_countries = nobel_df['birth_country'].value_counts().head(10)
top_countries.plot(kind='bar', figsize=(10, 5), color='skyblue')
plt.title("Top 10 Birth Countries of Nobel Laureates")
plt.ylabel("Number of Laureates")
plt.xticks(rotation=90)
plt.tight_layout()
plt.show()