Skip to content

Instantly share code, notes, and snippets.

@swinton
Created February 28, 2011 14:35
Show Gist options
  • Select an option

  • Save swinton/847392 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/847392 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
def fill_in_blanks(filename="data.csv", output="data-no-blanks.csv", interval=60):
f = csv.reader(open(filename))
out = csv.writer(open(output, "wb"))
last = None
# Deal with headers
out.writerow(f.next())
for line in f:
when, how_many = map(int, line)
if last is None:
last = when
# Fill in blanks
while last + interval < when:
last += interval
out.writerow((last, 0,))
out.writerow((when, how_many,))
last = when
if __name__ == "__main__":
fill_in_blanks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment