Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import csv
from collections import defaultdict
with open('/Users/adam/Downloads/languages-2014.csv', 'r') as f:
results_2014 = [row for row in csv.reader(f)][1:]
with open('/Users/adam/Downloads/languages-2013.csv', 'r') as f:
results_2013 = [row for row in csv.reader(f)][1:]
with open('/Users/adam/Downloads/languages-2012.csv', 'r') as f:
results_2012 = [row for row in csv.reader(f)][1:]
ranks_by_language = defaultdict(list)
installs_by_language = defaultdict(list)
for ii, row in enumerate(results_2014):
ranks_by_language[row[0]].append(ii + 1)
installs_by_language[row[0]].append(int(row[1]))
for ii, row in enumerate(results_2013):
ranks_by_language[row[0]].append(ii + 1)
installs_by_language[row[0]].append(int(row[1]))
for ii, row in enumerate(results_2012):
ranks_by_language[row[0]].append(ii + 1)
installs_by_language[row[0]].append(int(row[1]))
ranks_by_language['Clojure']
installs_by_language['Clojure']
installs_by_language['Java']
ranking_list = [(key, ranks[0]) for key, ranks in ranks_by_language.items()]
out = []
for lang, _ in sorted(ranking_list, key=lambda r: r[1]):
try:
rank2014 = ranks_by_language[lang][0]
rank2013 = ranks_by_language[lang][1]
rank2012 = ranks_by_language[lang][2]
if rank2014 <= 20 or rank2013 <= 20 or rank2012 <= 20:
out.append((
lang,
ranks_by_language[lang][0],
ranks_by_language[lang][1],
ranks_by_language[lang][2],
installs_by_language[lang][0],
installs_by_language[lang][1],
installs_by_language[lang][2],
))
except IndexError:
continue
with open('languages-compared.csv', 'w') as f:
w = csv.writer(f)
w.writerow(['Language', '2014 Rank', '2013 Rank', '2012 Rank', '2014 # Created', '2013 #', '2012 #'])
for row in out:
w.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment