我们都知道诺贝尔奖一般每年都会颁发给在全球做出突出贡献的科学家们,那么本次实验就来认真研究一下1901年至2020年间诺贝尔奖获得者的信息,选用数据集为有关诺贝尔奖获得者的个人信息,共14个特征,主要包括获奖者
# 导入相关库
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
pd.options.mode.chained_assignment = None
nobel = pd.read_csv('nobel_final.csv')
nobel_bron_country = nobel['born_country_code'].value_counts().to_frame()
nobel_bron_country = nobel_bron_country[nobel_bron_country['born_country_code'] >= 10]
# 绘制
plt.figure(figsize=(15, 5))
sns.barplot(x = nobel_bron_country.index , y = 'born_country_code' ,data = nobel_bron_country)
plt.xlabel('Country Code')
plt.ylabel('Number of Nobel winner')
plt.title("Most Nobel Winner Countries")
plt.show()
imigrate_nobel_winner = nobel.loc[(nobel['born_country_code'] != nobel['died_country_code'])]
imigrate_nobel_winner.dropna(subset=['died_country_code'] , inplace=True)
print( str(len(imigrate_nobel_winner)) + ' Nobel winners that bron country and died country are diffrent')
190 Nobel winners that bron country and died country are diffrent
imigrate_nobel_winner_born_country = imigrate_nobel_winner['born_country_code'].value_counts().to_frame()
imigrate_nobel_winner_born_country = imigrate_nobel_winner_born_country[imigrate_nobel_winner_born_country['born_country_code'] >= 5]
plt.figure(figsize=(15, 5))
sns.barplot(x = imigrate_nobel_winner_born_country.index , y = 'born_country_code' ,data = imigrate_nobel_winner_born_country)
plt.title("Most Immigrants Countries")
plt.xlabel('Country Code')
plt.ylabel('Number of Nobel winner')
plt.show()
imigrate_nobel_winner_died_country = imigrate_nobel_winner['died_country_code'].value_counts().to_frame()
imigrate_nobel_winner_died_country = imigrate_nobel_winner_died_country[imigrate_nobel_winner_died_country['died_country_code'] >= 5]
plt.figure(figsize=(15, 5))
sns.barplot(x = imigrate_nobel_winner_died_country.index , y = 'died_country_code' ,data = imigrate_nobel_winner_died_country)
plt.xlabel('Country Code')
plt.ylabel('Number of Nobel winner')
plt.title("Countries with the highest number of immigrant admissions")
plt.show()
nobel_winner_gender = nobel['gender'].value_counts().to_frame()
plt.figure(figsize=(15, 5))
sns.barplot(x = nobel_winner_gender.index , y = 'gender' ,data = nobel_winner_gender)
plt.xlabel('Gender')
plt.ylabel('Number of Nobel winner')
plt.title("Gender ratio of winners")
plt.show()
nobel_winner_year = nobel['year'].value_counts(ascending = True).to_frame()
nobel_winner_year = nobel_winner_year[nobel_winner_year['year'] >= 10]
plt.figure(figsize=(20, 5))
sns.barplot(x = nobel_winner_year.index , y = 'year' ,data = nobel_winner_year)
plt.xlabel('Year')
plt.ylabel('Number of Prize')
plt.title("Number of winners per year")
plt.xticks(rotation = 90)
plt.show()
winner_category = nobel['category'].value_counts().to_frame()
plt.figure(figsize=(20, 5))
sns.barplot(x = winner_category.index , y = 'category' ,data = winner_category)
plt.xlabel('Category')
plt.ylabel('Number of prize')
plt.title("Number of prize per category")
plt.show()
category_and_gender_winner = nobel.groupby('category')['gender'].value_counts().to_frame()
category_and_gender_winner.columns = ['number of winners']
category_and_gender_winner.reset_index(inplace=True)
plt.figure(figsize=(20, 5))
sns.barplot(x = 'category' , y = 'number of winners' , hue = 'gender' ,data = category_and_gender_winner)
plt.xlabel('Category')
plt.ylabel('Number of winners')
plt.title("Category By Gender")
plt.show()
nobel_university_winner = nobel['name_of_university'].value_counts().to_frame()
nobel_university_winner = nobel_university_winner[nobel_university_winner['name_of_university'] >= 10]
plt.figure(figsize=(10, 5))
sns.barplot(y = nobel_university_winner.index , x = 'name_of_university' ,data = nobel_university_winner ,palette = sns.color_palette('Set2'))
plt.xlabel('Number of Prize')
plt.ylabel('University')
plt.title("Top Universities that Nobel winners studied there")
plt.show()
nobel_country_winner = nobel['country_of_university'].value_counts().to_frame()
nobel_country_winner = nobel_country_winner[nobel_country_winner['country_of_university'] >= 5]
plt.figure(figsize=(10, 5))
sns.barplot(y = nobel_country_winner.index , x = 'country_of_university' ,data = nobel_country_winner ,palette = sns.color_palette('Set2'))
plt.xlabel('Number of Prize')
plt.ylabel('Country of University')
plt.title("Top Country of universities that Nobel winners studied there")
plt.show()
下面我们研究一下这些顶尖大学中其获奖者主要在哪些领域获奖的人数比较多
fulprize_university = nobel[(nobel['name_of_university'] == 'University of California')
| (nobel['name_of_university'] == 'Harvard University')
| (nobel['name_of_university'] == 'Massachusetts Institute of Technology (MIT)')
| (nobel['name_of_university'] == 'Stanford University')
| (nobel['name_of_university'] == 'University of Chicago')
| (nobel['name_of_university'] == 'University of Cambridge')
| (nobel['name_of_university'] == 'California Institute of Technology (Caltech)')
| (nobel['name_of_university'] == 'Columbia University')
| (nobel['name_of_university'] == 'Princeton University')
| (nobel['name_of_university'] == 'Rockefeller University')
| (nobel['name_of_university'] == 'MRC Laboratory of Molecular Biology')]
university_and_category = fulprize_university.groupby('name_of_university')['category'].value_counts().to_frame()
university_and_category.columns = ['number of prize']
university_and_category.reset_index(inplace= True)
plt.figure(figsize=(10, 5))
sns.barplot(y = 'name_of_university' , x = 'number of prize' , hue = 'category' , dodge = False ,data = university_and_category ,palette = sns.color_palette('Set2'))
plt.xlabel('Number of Prize')
plt.ylabel('Country of University')
plt.title("Top Universities and distribution of category")
plt.show()
nobel_country_winner_new = nobel_country_winner[nobel_country_winner['country_of_university'] >= 10]
fulprize_university_country = nobel[(nobel['country_of_university'] == 'USA')
| (nobel['country_of_university'] == 'United Kingdom')
| (nobel['country_of_university'] == 'Germany')
| (nobel['country_of_university'] == 'France')
| (nobel['country_of_university'] == 'Switzerland')
| (nobel['country_of_university'] == 'Japan')
| (nobel['country_of_university'] == 'Sweden')
| (nobel['country_of_university'] == 'the Netherlands')]
country_university_and_category = fulprize_university_country.groupby('country_of_university')['category'].value_counts().to_frame()
country_university_and_category.columns = ['Number of Prize']
country_university_and_category.reset_index(inplace=True)
plt.figure(figsize=(10, 5))
sns.barplot(y = 'country_of_university' , x = 'Number of Prize' , hue = 'category' ,dodge = False ,data = country_university_and_category ,palette = sns.color_palette('Set2'))
plt.xlabel('Number of Prize')
plt.ylabel('Country of University')
plt.title("Top Counties and distribution of category")
plt.show()
plt.figure(figsize=(15, 5))
sns.distplot(nobel['age'])
plt.xlabel('Age')
plt.title('Age get prize distribution')
plt.title("Distribution of Age Winners")
plt.show()
plt.figure(figsize=(15, 5))
sns.distplot(nobel['age_get_prize'])
plt.xlabel('Age get prize')
plt.title('Age get prize distribution')
plt.show()
plt.figure(figsize=(15, 5))
plot = sns.jointplot(x='age', y='age_get_prize' , kind='hex' ,data=nobel)
plot.set_axis_labels('x', 'y', fontsize=12)
plot.ax_joint.set_xlabel('Age')
plot.ax_joint.set_ylabel('Age of winner when get prize')
plt.title("Distribution of Age Winners VS Age of winners when get prize")
plt.tight_layout()
plt.figure(figsize=(15, 5))
sns.boxplot(x='gender', y='age', data=nobel)
plt.ylabel('Age')
plt.xlabel('Gender')
plt.title('Age average seprated by gender')
plt.show()
plt.figure(figsize=(15, 5))
sns.swarmplot(x='gender', y='age_get_prize',hue = 'category', dodge=True , data=nobel)
plt.ylabel('Age when get prize')
plt.xlabel('Gender')
plt.title('Every winner age seperated by gender and prize category')
plt.show()
plt.figure(figsize=(15, 6))
sns.kdeplot(nobel.age[nobel.category == 'chemistry'], label='chemistry', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'economics'], label='economics', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'peace'], label='peace', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'literature'], label='literature', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'physics'], label='physics', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'medicine'], label='medicine', shade=True)
sns.kdeplot(nobel.age[nobel.category == 'chemistry'], label='chemistry', shade=True)
plt.xlabel('Age')
plt.title('Age distribution on category of winners')
who_won_more_than_one = nobel[nobel.duplicated(subset=['firstname','surname'], keep= False)]\
[["firstname","surname","year", "age_get_prize", "gender","born_country_code", "died_country_code"]].reset_index()
who_won_more_than_one["difference_between_two_prize"] = who_won_more_than_one.groupby("surname")["year"].diff().abs()
who_won_more_than_one.bfill()
plt.figure(figsize = (16, 7))
sns.barplot(x= "firstname", y= "difference_between_two_prize", hue= "gender",
dodge=False, data= who_won_more_than_one, palette="Set1")
plt.xlabel("firstname")
plt.ylabel("Years Betwen two Prizes")
plt.title("Time difference between two awards")
plt.show()
数据集下载链接如下:https://github.com/NuanBaobao/Data-Visualization/blob/main/Exp7/noble.zip
参考资源:
https://www.cnblogs.com/cgmcoding/p/13356745.html
https://www.cnblogs.com/cgmcoding/p/13384442.html
https://cloud.tencent.com/developer/article/1517200
https://zhuanlan.zhihu.com/p/347067055