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
# Start coding here!# read df
import pandas as pd
df_nobel=pd.read_csv("data/nobel.csv")
print(df_nobel.head())
print(df_nobel.columns)
print(df_nobel.describe())
print(df_nobel.info())# 1-What is the most commonly awarded gender and birth country?
top_gender=pd.DataFrame()
top_gender["sex"] = df_nobel["sex"]
top_gender["laureate_id"] = df_nobel["laureate_id"]
top_gender= top_gender["sex"].value_counts(sort=True)
top_gender = top_gender.reset_index()
print(top_gender.columns)
print(top_gender.info())
top_gender = top_gender.loc[0,"index"]
#top_gender = top_gender["index"].values(0)
print(top_gender)
#print(top_gender.head())
#print(top_gender.info)
#print(top_gender)
top_country=pd.DataFrame()
top_country["birth_country"] = df_nobel["birth_country"]
top_country["laureate_id"] = df_nobel["laureate_id"]
#print(top_country.info())
top_country = top_country["birth_country"].value_counts(sort=True)
top_country = top_country.reset_index()
top_country = top_country.loc[0, "index"] #result
print(top_country)
#print(top_country.info())
# 2-Which decade had the highest ratio of US-born Nobel Prize winners to total winners in all categories?
#create and add "decade" to df_nobel
for index, row in df_nobel.iterrows():
if (row["year"] >= 1900) & (row["year"] <1910):
df_nobel.at[index, "decade"] = "1900"
elif (row["year"] >= 1910) & (row["year"] <1920):
df_nobel.at[index, "decade"] = "1910"
elif (row["year"] >= 1920) & (row["year"] <1930):
df_nobel.at[index, "decade"] = "1920"
elif (row["year"] >= 1930) & (row["year"] <1940):
df_nobel.at[index, "decade"] = "1930"
elif (row["year"] >= 1940) & (row["year"] <1950):
df_nobel.at[index, "decade"] = "1940"
elif (row["year"] >= 1950) & (row["year"] <1960):
df_nobel.at[index, "decade"] = "1950"
elif (row["year"] >= 1960) & (row["year"] <1970):
df_nobel.at[index, "decade"] = "1960"
elif (row["year"] >= 1970) & (row["year"] <1980):
df_nobel.at[index, "decade"] = "1970"
elif (row["year"] >= 1980) & (row["year"] <1990):
df_nobel.at[index, "decade"] = "1980"
elif (row["year"] >= 1990) & (row["year"] <2000):
df_nobel.at[index, "decade"] = "1990"
elif (row["year"] >= 2000) & (row["year"] <2010):
df_nobel.at[index, "decade"] = "2000"
elif (row["year"] >= 2010) & (row["year"] <2020):
df_nobel.at[index, "decade"] = "2010"
elif (row["year"] >= 2020) & (row["year"] <2030):
df_nobel.at[index, "decade"] = "2020"
else:
df_nobel.at[index, "decade"] = "mistake"
#print(df_nobel["decade"])
df_nobel.decade = df_nobel.decade.astype("int64")
nobel_country=df_nobel.groupby("decade")["laureate_id"].count()
print(nobel_country.head())
#group_country=df_nobel.groupby("birth_country")["laureate_id"].count().sort_values(ascending=False)
#print(group_country)
nobel_usa=df_nobel[df_nobel["birth_country"] == "United States of America"]
nobel_usa= nobel_usa.groupby("decade")["laureate_id"].count()
print(nobel_usa.head())
max_decade_usa = (nobel_usa / nobel_country).idxmax() #result
print(max_decade_usa)
#check=df_nobel[df_nobel["decade"] == "mistake"]
#print(check.head())
#max_decade_USA = df_nobel.groupby("birth_country")["laureate_id"].count().sort_values(ascending=False)
#print(max_decade_USA.head())# 3- Which decade and Nobel Prize category combination had the highest proportion of female laureates?
for index, row in df_nobel.iterrows(): #create and add "laur_fem" column
if row["sex"] == "Female":
df_nobel.at[index, "laur_fem"] = 1
else:
df_nobel.at[index, "laur_fem"] = 0
#print(df_nobel.head())
max_fem = pd.DataFrame() # fill the df max_fem2
max_fem["decade"] = df_nobel["decade"]
max_fem["category"] = df_nobel["category"]
max_fem["laur_nb"] = 1
max_fem["laur_fem"] = df_nobel["laur_fem"]
#print(max_fem.columns)
#print(max_fem.shape) # 4 columns at this stage
max_fem1= max_fem.groupby(["decade","category"])[["laur_fem", "laur_nb"]].sum()
max_fem1["fem_laur"]= max_fem1["laur_fem"] *100 / max_fem1["laur_nb"]
max_fem1["fem_laur"] = max_fem1["fem_laur"].round(1)
max_fem2 = max_fem1.sort_values(["fem_laur"],ascending=False)
print(max_fem2)
max_fem2= max_fem2.reset_index()
print(max_fem2)
max_female_dict = {max_fem2["decade"].values[0]:max_fem2["category"].values[0]}
print(max_female_dict)
# 4-First woman to win a nobel prize and in what category?
df_wom = pd.DataFrame()
df_wom["year"] = df_nobel["year"]
df_wom["full_name"] = df_nobel["full_name"]
df_wom["sex"] = df_nobel["sex"]
df_wom["category"]= df_nobel["category"]
df_wom = df_wom[df_wom["sex"] == "Female"]
df_wom= df_wom.sort_values(["year"], ascending=True)
print(df_wom.head())
first_woman_name = df_wom.iloc[0,1]
first_woman_category = df_wom.iloc[0,3]
print(first_woman_name) #result
print(first_woman_category) #result
# 5-Which individuals or organizations have won more than one Nobel Prize throughout the years?
#subset = ["laureate_id", "full_name", "organization_name" ]
# list of organization with more than 1 win
df_repeat = pd.DataFrame()
df_repeat["laureate_id"] = df_nobel["laureate_id"]
df_repeat["full_name"] = df_nobel["full_name"]
df_repeat["organization_name"] = df_nobel["organization_name"]
#print(df_repeat)
#orga_repeat = df_repeat.groupby("organization_name")["laureate_id"].count().sort_values() >1
#indiv_repeat = df_repeat.groupby("full_name")["laureate_id"].count().sort_values()>1
#df_repeat_org = pd.DataFrame()
#df_repeat_org["repeat"]= (df_repeat.groupby("organization_name")["laureate_id"].count())
#print(df_repeat_org[df_repeat_org["repeat"]>1])
#list_orga = (df_repeat_org[df_repeat_org["repeat"]>1])
#list_orga=list_orga.index.tolist()
#print(type(list_orga))
#print(list_orga)
# list of individuals with more than 1 win
df_repeat_ind = pd.DataFrame()
df_repeat_ind["repeat"]=(df_repeat.groupby("full_name")["laureate_id"].count())
#print(df_repeat_ind[df_repeat_ind["repeat"] >1])
list_ind = (df_repeat_ind[df_repeat_ind["repeat"] >1])
list_ind= (df_repeat_ind[df_repeat_ind["repeat"] > 1])
list_ind = list_ind.index.tolist()
#print(type(list_ind))
print(list_ind)
repeat_list = list_ind #list_orga + #result
#print(repeat_list)
#print(orga_repeat)
#print(orga_repeat.shape)
#orga_repeat=(df_repeat[orga_repeat])
#print(orga_repeat)
#| (df_repeat.groupby("full_name")["laureate_id"].count()>1)
#print(repeat)
#print(df_repeat[repeat])
#orga = df_repeat["organization_name"].tolist()
#indiv = df_repeat["full_name"].tolist()
#print(orga)
#print(indiv)
#print(orga_repeat)
#print(indiv_repeat)
#repeat_list = df_nobel["full_name"] * (indiv_repeat == True) & df_nobel["organization_name"]*(orga_repeat == True)
#print(repeat_list)#LEFTOVER from question 3
#print(max_fem3)
#print(max_fem3.info)
#max_fem3 = max_fem3.index
#print(max_fem3)
#print(max_fem2.head)
#max_fem3= max_fem2.index
#max_fem4 = max_fem3
#print(max_fem1)
#print(max_fem1.info())
#print(max_fem1.shape)
#max_fem2= max_fem.groupby(["decade","category"])["laur_nb","laur_fem"].sum()
#max_fem2["max_female"] = max_fem2["laur_fem"] * 100 / max_fem2["laur_nb"]
#max_fem2=max_fem2.round(1)
#print(max_fem2.head(15))
#print(max_fem2.info())
#print(max_fem2[["max_female"]])
#print(max_fem2.columns)
#print(max_fem2.shape)
#max_fem3 = pd.DataFrame()
#max_fem3 = max_fem2[["decade", "category", "max_female"]]
#max_fem3 =max_fem2["max_female"].idxmax()
#max_fem3 =max_fem2["max_female"].sort_values(ascending= False)
#print(max_fem3) #[["decade", "category"]])
#print(max_fem3.info())
#max_female = pd.DataFrame()
#max_female["decade"] = max_fem3["decade"]
#print(max_female)
#max_fem3=max_fem2[max_fem2[["decade", "category"]]
#max_fem3["category"]=max_fem2[max_fem2["category"]]
#max_female_dict = max_fem3.to_dict() # transfrom into a dictionnary
#print(max_female_dict)
#for key in range (1,1):
# decade, max = max_female_dict(key)
#print(max_female_dict["2020's"])
#max_female_dict.items()
#from itertools import islice
#max_female_dict=dict(islice(max_female_dict.items(),1))
#print(max_female_dict)
#LEFTOVER
#df_nobel["laur_fem"]
#(df_nobel.info())
#df_nobel["laur_nb"]= df_nobel["laureate_id"].count()
#print(df_nobel.head(10))
#print(df_nobel["laur_nb"].head(10))
#df_nobel.pivot_table(values ="laureate_id", index="decade" , columns = "category", aggfunc="count")
#print(df_nobel["sex"])
#df_nobel.pivot_table(values ="laur_fem", index="decade" , columns = "category", aggfunc="sum")
#max_fem["laur_fem"] = df_nobel.groupby("decade")["laur_fem"].sum()
#max_fem["laur_nb"] = df_nobel.groupby("decade")["laur_nb"].count()
#max_fem["category"] = df_nobel["category"]
#max_fem["max_female"] = max_fem["laur_fem"] *100/max_fem["laur_nb"]
#max_fem["max_female"] = max_fem["max_female"].round(1)
#print(max_fem.head())
#max_fem = pd.DataFrame()
#max_fem[] == df_nobel["decade"]# Calculate the proportion of USA born winners per decade
df_nobel['usa_born_winner'] = df_nobel['birth_country'] == 'United States of America'
df_nobel['decade'] = (np.floor(df_nobel['year'] / 10) * 10).astype(int)
prop_usa_winners = df_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]
print(df_nobel["usa_born_winner"])
print(prop_usa_winners)
# 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]
# 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]
# 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]}
# 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]
# 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(prop_usa_winners.info)
#print(prop_usa_winners.columns)
#print(prop_usa_winners)
#print(prop_female_winners)
#print(max_female_decade_category)
print(nobel_women)