Skip to content

Instantly share code, notes, and snippets.

@xdhmoore
Last active January 2, 2016 18:29
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 xdhmoore/2251e24346dc93b25d39 to your computer and use it in GitHub Desktop.
Save xdhmoore/2251e24346dc93b25d39 to your computer and use it in GitHub Desktop.
Manipulate GitHub Archive data downloaded from Google BigQuery in order to make a graph in Excel. Transforms CSV of form: [watchers, repository_name, parsed_date] to form: [date, backbone count, angular.js count, ember.js count, knockout count]
import csv
names = sorted(['backbone', 'angular.js', 'ember.js', 'knockout'])
with open('in.csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
dates = {}
next(reader)
for row in reader:
count = row[0]
framework = row[1]
date = row[2]
if date not in dates:
dates[date] = {}
dates[date][framework] = count
header = 'date'
for n in names:
header += ',' + n + ''
header += ''
print(header)
for date in sorted(dates):
for n in names:
if n not in dates[date]:
dates[date][n] = ''
line = '' + date + ''
for name in names:
line += ',' + dates[date][name] + ''
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment