1 from csv import DictReader
3 # read in the input file and count by day
4 input_file = open("hp_wiki.csv", 'r')
7 for row in DictReader(input_file):
8 day_string = row['timestamp'][0:10]
10 if day_string in edits_by_day:
11 edits_by_day[day_string] = edits_by_day[day_string] + 1
13 edits_by_day[day_string] = 1
17 # output the counts by day
18 output_file = open("hp_edits_by_day.csv", "w")
21 output_file.write("date,edits\n")
23 # iterate through every day and print out data into the file
24 for day_string in edits_by_day:
25 output_file.write(",".join([day_string, str(edits_by_day[day_string])]) + "\n")