Skip to content

Instantly share code, notes, and snippets.

@philshem
Last active October 8, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philshem/a778945f5114edad3c2e5a91564601fb to your computer and use it in GitHub Desktop.
Save philshem/a778945f5114edad3c2e5a91564601fb to your computer and use it in GitHub Desktop.
Nobel prize winners and their years until death.
#/usr/bin/python3
# gets demographics for nobel prize winners
# calculates yearly average of how many years between prize and death
import pandas as pd
import numpy as np
# api endpoint for all nobel winnters: https://nobelprize.readme.io/
url = 'http://api.nobelprize.org/v1/laureate.csv'
# import csv from web API
df = pd.read_csv(url)
# convert strings to datetime
df['died'] = pd.to_datetime(df.died, format='%Y-%m-%d', errors='coerce')
df['year_date'] = pd.to_datetime(df.year, format='%Y', errors='coerce')
# calculate difference between death and prize years
df['years_until_death'] = (df['died'] - df['year_date'])/np.timedelta64(1,'Y')
# get mean years until death for each prize year
df = df.groupby('year')['years_until_death'].mean().round()
# write to csv
df.to_csv('nobel_prize_years_until_death.csv', header=True)
year years_until_death
1901 13.0
1902 19.0
1903 11.0
1904 17.0
1905 16.0
1906 16.0
1907 17.0
1908 14.0
1909 17.0
1910 14.0
1911 19.0
1912 29.0
1913 20.0
1914 28.0
1915 35.0
1916 24.0
1917 19.0
1918 23.0
1919 23.0
1920 22.0
1921 19.0
1922 32.0
1923 17.0
1924 20.0
1925 27.0
1926 14.0
1927 21.0
1928 23.0
1929 23.0
1930 18.0
1931 15.0
1932 27.0
1933 30.0
1934 27.0
1935 19.0
1936 31.0
1937 29.0
1938 28.0
1939 33.0
1943 32.0
1944 23.0
1945 19.0
1946 19.0
1947 21.0
1948 21.0
1949 22.0
1950 20.0
1951 28.0
1952 32.0
1953 18.0
1954 29.0
1955 37.0
1956 24.0
1957 24.0
1958 27.0
1959 29.0
1960 25.0
1961 24.0
1962 30.0
1963 23.0
1964 29.0
1965 24.0
1966 14.0
1967 27.0
1968 22.0
1969 23.0
1970 30.0
1971 13.0
1972 24.0
1973 20.0
1974 15.0
1975 21.0
1976 34.0
1977 16.0
1978 14.0
1979 18.0
1980 30.0
1981 22.0
1982 21.0
1983 15.0
1984 14.0
1985 24.0
1986 23.0
1987 9.0
1988 19.0
1989 16.0
1990 17.0
1991 21.0
1992 21.0
1993 21.0
1994 14.0
1995 13.0
1996 14.0
1997 21.0
1998 12.0
1999 18.0
2000 13.0
2001 16.0
2002 13.0
2003 9.0
2004 10.0
2005 10.0
2006
2007 7.0
2008 9.0
2009 6.0
2010 5.0
2011 2.0
2012 4.0
2013
2014
2015
2016 3.0
2017
2018
2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment