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!
import pandas as pd
import seaborn as sns
import numpy as np
nobel = pd.read_csv("data/nobel.csv")
#What is the most commonly awarded gender and birth country?
top_gender = nobel['sex'].value_counts().index[0]
top_country = nobel['birth_country'].value_counts().index[0]
print(top_gender, top_country)
#Identify the decade with the highest proportion of US-born winners
#First making a column with a T/F flag to identify USA-born winners
nobel['usa_born_winner']=nobel['birth_country']=='United States of America'
nobel.head(100)
#Next creating a decade column, using np.floor(), and ensuring 'year' col is int64
nobel['year'].dtype
nobel['decade'] = nobel['year'].transform(lambda x: np.floor(x/10)*10).astype(int)
#get the average of usa-born winners for each decade in a DataFrame
decade_perc = nobel.groupby('decade', as_index=False)['usa_born_winner'].mean()
#identify the decade w/ the highest proportion of US-born winners
max_row=decade_perc[decade_perc['usa_born_winner']==decade_perc['usa_born_winner'].max()].values[0]
max_row = int(max_row[0])
max_row
#Visualized the Proportion of US-born Winners by Decade w/ a Line plot
import matplotlib.pyplot as plt
import seaborn as sns
g=sns.relplot(kind='line', data=decade_perc, x='decade', y='usa_born_winner')
g.fig.suptitle("Proportion of US-born Winners by Decade")
g.set(xlabel='Decade', ylabel='Proportion of US-born Winners')
#which decade and category had the highest proportion of female winners?
nobel['female_winner']= nobel['sex']=='Female'
nobel_female = nobel.groupby(['decade', 'category'],as_index=False)['female_winner'].mean()
max_female_row = nobel_female[nobel_female['female_winner']==nobel_female['female_winner'].max()].values[0]
max_female_row
#my alternate solution to the above line
#nobel_female_sorted = nobel_female.sort_values('female_winner', ascending=False).head(1)
max_female_dict = {max_female_row[0]: max_female_row[1]}
max_female_dict
#my alternate to the above lines
#max_female_dict = max_female_row.set_index('decade')['category'].to_dict()
#max_female_dict
#showing the proportion of female winners grouped by decade and category
g=sns.relplot(kind='line', data=nobel_female, x='decade', y='female_winner', hue='category')
g.fig.suptitle("Proportion of Female Winners by Decade and Category")
g.set(xlabel='Decade', ylabel='Proportion of Female Winners')
#Who was the first woman to receive a Nobel Prize, and in what category?
#save answers as a string
nobel_female_filter = nobel[nobel['female_winner']==True]
min_row = nobel_female_filter[nobel_female_filter['year']==nobel_female_filter['year'].min()]
first_woman_name = min_row['full_name']
first_woman_category = min_row['category']
first_woman_name = first_woman_name.values[0]
first_woman_category = first_woman_category.values[0]
display(first_woman_name,first_woman_category)
#determining winners that won the prize for 2 or more times, answers in a list
name_count = nobel['full_name'].value_counts()
subset_name_count = name_count[name_count >= 2].index
repeat_list = list(subset_name_count)
repeat_list