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
# Start coding here!df = pd.read_csv('data/nobel.csv')
df.head()top_gender = df['sex'].value_counts().idxmax()
top_country = df['birth_country'].value_counts().idxmax()
print(top_gender, top_country)import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Create a new column 'decade' by flooring the 'year' divided by 10 and multiplying by 10 to get the decade
df['decade'] = np.floor(df['year'] / 10) * 10
# Convert the 'decade' column to integer type
df['decade'] = df['decade'].astype(int)
# Group the dataframe by the 'decade' column
grouped = df.groupby('decade')
# Define a function to calculate the ratio of USA-born laureates in a given group
def usa_born_ratio_per_decade(group_df):
return (group_df['birth_country'] == 'United States of America').mean()
# Apply the function to each group and reset the index to get a dataframe with 'decade' and 'usa_born_ratio' columns
usa_born_ratios = grouped.apply(usa_born_ratio_per_decade).reset_index(name='usa_born_ratio')
# Find the decade with the highest USA-born ratio
max_decade_usa = usa_born_ratios.loc[usa_born_ratios['usa_born_ratio'].idxmax(), 'decade']
# Display the decade with the highest USA-born ratio
print('The decade with the highest USA-born ratio', max_decade_usa)
# Create a point plot of the USA-born ratio per decade
sns.pointplot(x='decade', y='usa_born_ratio', data=usa_born_ratios)
# Set the title of the plot
plt.title('USA-born Nobel Laureates Ratio per Decade')
# Set the x-axis label
plt.xlabel('Decade')
# Set the y-axis label
plt.ylabel('USA-born Ratio')
# Display the plot
plt.show()# Group the dataframe by the 'decade' and 'category' column
grouped2 = df.groupby(['decade', 'category'])
# Define a function to calculate the ratio of female laureates in a given group
def female_ratio_per_decade(group_df):
return (group_df['sex'] == 'Female').mean()
# Apply the function to each group and reset the index to get a dataframe with 'decade' and 'female_ratio' columns
female_ratios = grouped2.apply(female_ratio_per_decade).reset_index(name='female_ratio')
# Find the decade and category with the highest female ratio
max_female_row = female_ratios.loc[female_ratios['female_ratio'].idxmax()]
# max_female_dict = {'decade': max_female_row['decade'], 'category': max_female_row['category']}
# Create a point plot of the female ratio per decade
sns.lineplot(x='decade', y='female_ratio', data=female_ratios, markers=True, hue='category', style='category')
# Set the title of the plot
plt.title('Female Nobel Laureates Ratio per Decade')
# Set the x-axis label
plt.xlabel('Decade')
# Set the y-axis label
plt.ylabel('Female Ratio')
# Display the plot
plt.show()
# Calculating the proportion of female laureates per decade
df['female_winner'] = df['sex'] == 'Female'
prop_female_winners = 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 = {
'decade': max_female_decade_category['decade'].values[0],
'category': max_female_decade_category['category'].values[0]
}
max_female_dictfirst_woman_to_win_np = df[df['sex'] == 'Female'].sort_values(by='year', ascending=True)['full_name'].iloc[0]
print('The first woman to win a noble prize is', first_woman_to_win_np)# repeats = df[df['full_name'].duplicated(keep=False)]['full_name'].sort_values(ascending=False).mode()
df2 = df[df['full_name'].duplicated(keep=False)]['full_name'].sort_values(ascending=False)
def amount_of_wins_per_laureat(count_df):
return count_df.count()
repeats = df2.groupby(df2).apply(amount_of_wins_per_laureat).reset_index(name='count')
repeats# Loading in required libraries
import pandas as pd
import seaborn as sns
import numpy as np
# Read in the Nobel Prize data
nobel = pd.read_csv('data/nobel.csv')
# Store and display the most commonly awarded gender and birth country in requested variables
top_gender = nobel['sex'].value_counts().index[0]
top_country = nobel['birth_country'].value_counts().index[0]
print("\n The gender with the most Nobel laureates is :", top_gender)
print(" The most common birth country of Nobel laureates is :", top_country)
# Calculate the proportion of USA born winners per decade
nobel['usa_born_winner'] = nobel['birth_country'] == 'United States of America'
nobel['decade'] = (np.floor(nobel['year'] / 10) * 10).astype(int)
prop_usa_winners = nobel.groupby('decade', as_index=False)['usa_born_winner'].mean()
# Identify the decade with the highest proportion of US-born winners
max_decade_usa = prop_usa_winners[prop_usa_winners['usa_born_winner'] == prop_usa_winners['usa_born_winner'].max()]['decade'].values[0]
# Optional: Plotting USA born winners
ax1 = sns.relplot(x='decade', y='usa_born_winner', data=prop_usa_winners, kind="line")
# Calculating the proportion of female laureates per decade
nobel['female_winner'] = nobel['sex'] == 'Female'
prop_female_winners = nobel.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[nobel['female_winner']]
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}.")
# Selecting the laureates that have received 2 or more prizes
counts = nobel['full_name'].value_counts()
repeats = counts[counts >= 2].index
repeat_list = list(repeats)
print("\n The repeat winners are :", repeat_list)