Skip to content

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  # Importing the missing library

# Start coding here!
nobel = pd.read_csv('data/nobel.csv')
# print(nobel[['sex', 'birth_country']])


# What is the most commonly awarded gender and birth country?
# Store your answers as string variables top_gender and top_country
top_gender = nobel['sex'].mode().iloc[0]
top_country = nobel['birth_country'].mode().iloc[0]
# print(f'{top_gender}\n{top_country}')


# Which decade had the highest ratio of US-born Nobel Prize winners to total winners in all categories?
nobel['US_born_column'] = nobel['birth_country'] == 'United States of America'  # Creating a US-born winners column
nobel['decade'] = (nobel['year'] // 10) * 10    # creating a decade column
decade_sums = nobel.groupby('decade')['US_born_column'].sum().reset_index()    # Group by decade and give the number of winners in each decade
decade_sums = decade_sums.rename(columns={'US_born_column': 'total_winner(s)'}) # rename the column "US_born_column" to "total_winner(s)"
total_decade_sums = decade_sums['total_winner(s)'].sum() # total sum all the US_born_column values
decade_sums['ratio'] = decade_sums['total_winner(s)'] / total_decade_sums    # ratio for each decade to total decades
max_decade_usa = decade_sums.loc[decade_sums['ratio'].idxmax(), 'decade']    # select decade ratio with max ratio
# print(decade_sums)
# print(total_decade_sums)
# print(max_decade_usa)
plt.plot(decade_sums['decade'], decade_sums['total_winner(s)'], marker='o', color='b', label='Total Winners')
plt.plot(decade_sums['decade'], decade_sums['ratio'], marker='s', color='r', label='Ratio')
plt.xlabel('Decade')
plt.ylabel('Values')
plt.title('Total winners and ratio per decade')
plt.legend()
plt.grid(True)
plt.show()


# Which decade and Nobel Prize category combination had the highest proportion of female laureates?
# Create a column indicating whether the laureate is female
nobel['is_female'] = nobel['sex'] == 'Female'

# Group by decade and category, then calculate the total count and female count
group_combination_count = nobel.groupby(['decade', 'category']).agg(
    total_counts=('sex', 'size'),
    female_counts=('is_female', 'sum')
).reset_index()

# Calculate the proportion of female laureates
group_combination_count['female_proportion'] = group_combination_count['female_counts'] / group_combination_count['total_counts']

# Find the combination with the highest proportion of female laureates
max_female_proportion = group_combination_count.loc[group_combination_count['female_proportion'].idxmax()]

# Convert the result to a dictionary
# max_female_dict = {
#    'decade': max_female_proportion['decade'],
#    'category': max_female_proportion['category']
# }
# or the code below to convert to dic
max_female_dict = dict(zip([max_female_proportion['decade']], [max_female_proportion['category']]))
print(group_combination_count)
print(max_female_dict)


# Who was the first woman to receive a Nobel Prize, and in what category?
nobel_female_winners = nobel[nobel['sex'] == 'Female']  # Extract only female winners from the DataFrame
sort_by_year = nobel_female_winners.sort_values('year') # Sort by year to make sure it's in order
first_woman_name = sort_by_year['full_name'].iloc[0]    # Select the first row of name using .iloc[0] where zero indicate 1st row
first_woman_category = sort_by_year['category'].iloc[0]  
# print(first_woman_name)
# print(first_woman_category)


# Which individuals or organizations have won more than one Nobel Prize throughout the years?
# Group by 'full_name' and count the occurrences
name_counts = nobel['full_name'].value_counts()

# Filter names with more than one win
repeat_winners = name_counts[name_counts > 1].index.tolist()

# Store the full names in a list named repeat_list
repeat_list = repeat_winners
print(repeat_list)