In [1]:
import pandas as pd, numpy as np
In [38]:
#load list of all circuits and years with races from wikipedia
df=pd.read_html('http://en.wikipedia.org/wiki/List_of_Formula_One_circuits', header=0)
In [41]:
df=df[2][['Circuit','Location','Season(s)','Map']]
In [81]:
#geocode circuit names and create list with circuits
from pygeocoder import Geocoder
circs=[]
apikey='AIzaSyCJJD4hDxsENJOVohntPCqgvsuvQ-yRgLY'
for i in df.T.iteritems():
    circ={}
    circ['name']=i[1][0]
    if repr(i[1][2]).lower()=='nan':
        circs[-1]['races']=circs[-1]['races']+', '+i[1][3]
    else:
        circ['races']=i[1][2]
        circ['place']=i[1][1]
        circ['coord']=Geocoder(apikey).geocode(circ['place']).coordinates
        circs.append(circ)
    print circs[-1]
{'races': u'1985\u20131995', 'place': u'Adelaide, Australia', 'name': u'Adelaide Street Circuit', 'coord': (-34.9284989, 138.6007456)}
{'races': u'1958', 'place': u'Casablanca, Morocco', 'name': u'Ain-Diab Circuit', 'coord': (33.5731104, -7.589843399999999)}
{'races': u'1955, 1957, 1959, 1961\u20131962', 'place': u'Aintree, United Kingdom', 'name': u'Aintree Motor Racing Circuit', 'coord': (53.486017, -2.9499065)}
{'races': u'1984\u20131996', 'place': u'Cascais, Portugal', 'name': u'Aut\xf3dromo do Estoril', 'coord': (38.6967571, -9.4207438)}
{'races': u'1980', 'place': u'Imola, Italy', 'name': u'Autodromo Enzo e Dino Ferrari', 'coord': (44.35999959999999, 11.7124294)}
{'races': u'1980, 1981\u20132006', 'place': u'Imola, Italy', 'name': u'Autodromo Enzo e Dino Ferrari', 'coord': (44.35999959999999, 11.7124294)}
{'races': u'1963\u20131970, 1986\u20131992, 2015\u20132017', 'place': u'Mexico City, Mexico', 'name': u'Aut\xf3dromo Hermanos Rodr\xedguez', 'coord': (19.4326077, -99.133208)}
{'races': u'1978, 1981\u20131989', 'place': u'Rio de Janeiro, Brazil', 'name': u'Aut\xf3dromo Internacional Nelson Piquet', 'coord': (-22.9068467, -43.1728965)}
{'races': u'1973\u20131977, 1979\u20131980, 1990\u20132017', 'place': u'S\xe3o Paulo, Brazil', 'name': u'Aut\xf3dromo Jos\xe9 Carlos Pace', 'coord': (-23.5505199, -46.63330939999999)}
{'races': u'1953\u20131958, 1960, 1972\u20131975, 1977\u20131981, 1995\u20131998', 'place': u'Buenos Aires, Argentina', 'name': u'Aut\xf3dromo Juan y Oscar G\xe1lvez', 'coord': (-34.6036844, -58.3815591)}
{'races': u'1950\u20131979, 1981\u20132017', 'place': u'Monza, Italy', 'name': u'Autodromo Nazionale Monza', 'coord': (45.5845001, 9.2744485)}
{'races': u'1959', 'place': u'Berlin, Germany', 'name': u'AVUS', 'coord': (52.52000659999999, 13.404954)}
{'races': u'2004\u20132010, 2012\u20132017', 'place': u'Sakhir, Bahrain', 'name': u'Bahrain International Circuit', 'coord': (26.0316, 50.51289999999999)}
{'races': u'2016', 'place': u'Baku, Azerbaijan', 'name': u'Baku City Circuit', 'coord': (40.40926169999999, 49.8670924)}
{'races': u'2016, 2017', 'place': u'Baku, Azerbaijan', 'name': u'Baku City Circuit', 'coord': (40.40926169999999, 49.8670924)}
{'races': u'1964, 1966, 1968, 1970, 1972, 1974, 1976, 1978, 1980, 1982, 1984, 1986', 'place': u'West Kingsdown, United Kingdom', 'name': u'Brands Hatch', 'coord': (51.342412, 0.261927)}
{'races': u'1964, 1966, 1968, 1970, 1972, 1974, 1976, 1978, 1980, 1982, 1984, 1986, 1983, 1985', 'place': u'West Kingsdown, United Kingdom', 'name': u'Brands Hatch', 'coord': (51.342412, 0.261927)}
{'races': u'2011\u20132013', 'place': u'Greater Noida, India', 'name': u'Buddh International Circuit', 'coord': (28.4743879, 77.50399039999999)}
{'races': u'1967', 'place': u'Le Mans, France', 'name': u'Bugatti Circuit', 'coord': (48.00611000000001, 0.199556)}
{'races': u'1981\u20131982', 'place': u'Las Vegas, United States', 'name': u'Caesars Palace Grand Prix Circuit', 'coord': (36.1699412, -115.1398296)}
{'races': u'1965, 1969\u20131970, 1972', 'place': u'Saint-Gen\xe8s-Champanelle, France', 'name': u'Charade Circuit', 'coord': (45.72031, 3.018367)}
{'races': u'1950\u20131954', 'place': u'Bern, Switzerland', 'name': u'Circuit Bremgarten', 'coord': (46.9479739, 7.4474468)}
{'races': u'1991\u20132017', 'place': u'Montmel\xf3, Spain', 'name': u'Circuit de Barcelona-Catalunya', 'coord': (41.5567683, 2.2507317)}
{'races': u'1950, 1955\u20132017', 'place': u'Monaco', 'name': u'Circuit de Monaco', 'coord': (43.73841760000001, 7.424615799999999)}
{'races': u'1950\u20131956, 1958, 1960\u20131968, 1970, 1983, 1985\u20132002, 2004\u20132005, 2007\u20132017', 'place': u'Stavelot, Belgium', 'name': u'Circuit de Spa-Francorchamps', 'coord': (50.3940981, 5.9304413)}
{'races': u'1959', 'place': u'Lisbon, Portugal', 'name': u'Circuito de Monsanto', 'coord': (38.7222524, -9.1393366)}
{'races': u'1991\u20132008', 'place': u'Magny-Cours, France', 'name': u'Circuit de Nevers Magny-Cours', 'coord': (46.8615409, 3.163392)}
{'races': u'1978\u20131986, 1988\u20132008, 2010\u20132017', 'place': u'Montreal, Quebec, Canada', 'name': u'Circuit Gilles Villeneuve', 'coord': (45.5016889, -73.567256)}
{'races': u'1968, 1970', 'place': u'Mont-Tremblant, Canada', 'name': u'Circuit Mont-Tremblant', 'coord': (46.1184616, -74.5961852)}
{'races': u'2012\u20132017', 'place': u'Elroy, Texas, United States', 'name': u'Circuit of the Americas', 'coord': (30.12077, -97.63527839999999)}
{'races': u'1952\u20131953, 1955, 1958\u20131971, 1973\u20131985', 'place': u'Zandvoort, Netherlands', 'name': u'Circuit Park Zandvoort', 'coord': (52.3711487, 4.533354999999999)}
{'races': u'1971, 1973, 1975\u20131976, 1978, 1980, 1982\u20131983, 1985\u20131990', 'place': u'Le Castellet, France', 'name': u'Circuit Paul Ricard', 'coord': (43.203551, 5.776755)}
{'races': u'1973, 1975\u20131982, 1984', 'place': u'Heusden-Zolder, Belgium', 'name': u'Circuit Zolder', 'coord': (51.0384819, 5.2904127)}
{'races': u'1958, 1960', 'place': u'Porto, Portugal', 'name': u'Circuito da Boavista', 'coord': (41.1579438, -8.629105299999999)}
{'races': u'1986\u20131990', 'place': u'Jerez de la Frontera, Spain', 'name': u'Circuito de Jerez', 'coord': (36.6850064, -6.126074399999999)}
{'races': u'1986\u20131990, 1994, 1997', 'place': u'Jerez de la Frontera, Spain', 'name': u'Circuito de Jerez', 'coord': (36.6850064, -6.126074399999999)}
{'races': u'1968, 1970, 1972, 1974, 1976\u20131979, 1981', 'place': u'San Sebasti\xe1n de los Reyes, Spain', 'name': u'Circuito del Jarama', 'coord': (40.5688791, -3.5913939)}
{'races': u'1984', 'place': u'Dallas, United States', 'name': u'Dallas Grand Prix Circuit', 'coord': (32.7766642, -96.79698789999999)}
{'races': u'1982\u20131988', 'place': u'Detroit, United States', 'name': u'Detroit street circuit', 'coord': (42.331427, -83.0457538)}
{'races': u'1974, 1977, 1979, 1981\u20131982, 1984', 'place': u'Prenois, France', 'name': u'Dijon-Prenois', 'coord': (47.376361, 4.905415)}
{'races': u'1993', 'place': u'Castle Donington, United Kingdom', 'name': u'Donington Park', 'coord': (52.845016, -1.3373001)}
{'races': u'1976\u20131977, 2007\u20132008', 'place': u'Oyama, Japan', 'name': u'Fuji Speedway', 'coord': (36.3146714, 139.800131)}
{'races': u'1976\u20131983', 'place': u'Long Beach, United States', 'name': u'Long Beach Street Circuit', 'coord': (33.7700504, -118.1937395)}
{'races': u'1970, 1977\u20131984, 1986\u20132006, 2008, 2010, 2012, 2014, 2016', 'place': u'Hockenheim, Germany', 'name': u'Hockenheimring', 'coord': (49.31955199999999, 8.5498581)}
{'races': u'1986\u20132017', 'place': u'Mogyor\xf3d, Hungary', 'name': u'Hungaroring', 'coord': (47.6001016, 19.2420461)}
{'races': u'1950\u20131960', 'place': u'Speedway, United States', 'name': u'Indianapolis Motor Speedway', 'coord': (39.792738, -86.250822)}
{'races': u'1950\u20131960, 04 !4.192\xa0km (2.605\xa0mi)', 'place': u'Speedway, United States', 'name': u'Indianapolis Motor Speedway', 'coord': (39.792738, -86.250822)}
{'races': u'2005\u20132011', 'place': u'Istanbul, Turkey', 'name': u'Istanbul Park', 'coord': (41.0082376, 28.9783589)}
{'races': u'2010\u20132013', 'place': u'Yeongam, South Korea', 'name': u'Korea International Circuit', 'coord': (34.8001685, 126.6967918)}
{'races': u'1967\u20131980, 1982\u20131985, 1992\u20131993', 'place': u'Midrand, South Africa', 'name': u'Kyalami Racing Circuit', 'coord': (-25.9991795, 28.1262927)}
{'races': u'2008\u20132017', 'place': u'Singapore', 'name': u'Marina Bay Street Circuit', 'coord': (1.352083, 103.819836)}
{'races': u'1996\u20132017', 'place': u'Melbourne, Australia', 'name': u'Melbourne Grand Prix Circuit', 'coord': (-37.8136276, 144.9630576)}
{'races': u'1969, 1971, 1973, 1975', 'place': u'Barcelona, Spain', 'name': u'Montju\xefc circuit', 'coord': (41.3850639, 2.1734035)}
{'races': u'1967, 1969, 1971\u20131974, 1976\u20131977', 'place': u'Bowmanville, Canada', 'name': u'Mosport International Raceway', 'coord': (43.9126042, -78.688019)}
{'races': u'1972, 1974', 'place': u'Nivelles, Belgium', 'name': u'Nivelles-Baulers', 'coord': (50.59787, 4.32851)}
{'races': u'1951\u20131954, 1956\u20131958, 1961\u20131969, 1971\u20131976, 1985, 2009, 2011, 2013', 'place': u'N\xfcrburg, Germany', 'name': u'N\xfcrburgring', 'coord': (50.3418803, 6.9520304)}
{'races': u'1951\u20131954, 1956\u20131958, 1961\u20131969, 1971\u20131976, 1985, 2009, 2011, 2013, 1984, 1995\u20131996, 1999\u20132007', 'place': u'N\xfcrburg, Germany', 'name': u'N\xfcrburgring', 'coord': (50.3418803, 6.9520304)}
{'races': u'1951\u20131954, 1956\u20131958, 1961\u20131969, 1971\u20131976, 1985, 2009, 2011, 2013, 1984, 1995\u20131996, 1999\u20132007, 1997\u20131998', 'place': u'N\xfcrburg, Germany', 'name': u'N\xfcrburgring', 'coord': (50.3418803, 6.9520304)}
{'races': u'1951, 1954', 'place': u'Barcelona, Spain', 'name': u'Pedralbes Circuit', 'coord': (41.3850639, 2.1734035)}
{'races': u'1957', 'place': u'Pescara, Italy', 'name': u'Pescara Circuit', 'coord': (42.4617902, 14.2160898)}
{'races': u'1989\u20131991', 'place': u'Phoenix, United States', 'name': u'Phoenix street circuit', 'coord': (33.4483771, -112.0740373)}
{'races': u'1962\u20131963, 1965', 'place': u'East London, South Africa', 'name': u'Prince George Circuit', 'coord': (-33.0291582, 27.8545867)}
{'races': u'1970\u20131987, 1997\u20132003, 2014\u20132017', 'place': u'Spielberg bei Knittelfeld, Austria', 'name': u'Red Bull Ring (formerly A1-Ring and \xd6sterreichring)', 'coord': (47.2085616, 14.7996235)}
{'races': u'1950\u20131951, 1953\u20131954, 1956, 1958\u20131961, 1963, 1966', 'place': u'Gueux, France', 'name': u'Reims-Gueux', 'coord': (49.248466, 3.90993)}
{'races': u'1960', 'place': u'Moreno Valley, United States', 'name': u'Riverside International Raceway', 'coord': (33.9424658, -117.2296717)}
{'races': u'1952, 1957, 1962, 1964, 1968', 'place': u'Orival, France', 'name': u'Rouen-Les-Essarts', 'coord': (49.310705, 0.996206)}
{'races': u'1973\u20131978', 'place': u'Anderstorp, Sweden', 'name': u'Scandinavian Raceway', 'coord': (57.2812542, 13.6271963)}
{'races': u'1959', 'place': u'Sebring, United States', 'name': u'Sebring International Raceway', 'coord': (27.495592, -81.440907)}
{'races': u'1999\u20132017', 'place': u'Sepang, Malaysia', 'name': u'Sepang International Circuit', 'coord': (2.691369, 101.7505271)}
{'races': u'2004\u20132017', 'place': u'Shanghai, China', 'name': u'Shanghai International Circuit', 'coord': (31.2303904, 121.4737021)}
{'races': u'1950\u20131954, 1956, 1958, 1960, 1963, 1965, 1967, 1969, 1971, 1973, 1975, 1977, 1979, 1981, 1983, 1985, 1987\u20132017', 'place': u'Silverstone, United Kingdom', 'name': u'Silverstone Circuit', 'coord': (52.091477, -1.0280609)}
{'races': u'2014\u20132017', 'place': u'Sochi, Russia', 'name': u'Sochi Autodrom', 'coord': (43.60280789999999, 39.7341543)}
{'races': u'1987\u20132006, 2009\u20132017', 'place': u'Suzuka, Japan', 'name': u'Suzuka Circuit', 'coord': (34.8818796, 136.5842092)}
{'races': u'1994\u20131995', 'place': u'Mimasaka, Japan', 'name': u'Okayama International Circuit', 'coord': (35.0085882, 134.1485722)}
{'races': u'2008\u20132012', 'place': u'Valencia, Spain', 'name': u'Valencia Street Circuit', 'coord': (39.4699075, -0.3762881)}
{'races': u'1961\u20131980', 'place': u'Watkins Glen, United States', 'name': u'Watkins Glen', 'coord': (42.3806287, -76.8732921)}
{'races': u'2009\u20132017', 'place': u'Abu Dhabi, United Arab Emirates', 'name': u'Yas Marina Circuit', 'coord': (24.453884, 54.3773438)}
{'races': u'1964', 'place': u'Zeltweg, Austria', 'name': u'Zeltweg Airfield', 'coord': (47.1898236, 14.7523616)}
In [82]:
#manual fixes
circs[41]['races']='1950-1960, 2000-2007'
In [83]:
calendar={i:[] for i in range(1950,2018)}
for i in range(len(circs)):
    for k in circs[i]['races'].replace(u'\u2013', '-').replace(" ", ",").replace(",,", ",").split(","):
        r=k.find('-')
        if r==-1:
            calendar[np.int(k)].append(i)
        else:
            for j in range(np.int(k[:r]),np.int(k[r+1:])+1):
                calendar[j].append(i)
In [84]:
#save data
import json
file('calendar2018.json','w').write(json.dumps(calendar))
file('circs2018.json','w').write(json.dumps(circs))