Created
February 28, 2011 14:35
-
-
Save swinton/847392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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