Skip to content

Commit

Permalink
fixed bug in data reader
Browse files Browse the repository at this point in the history
  • Loading branch information
BinRoot committed May 2, 2017
1 parent 8427610 commit 163c15e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ch03_regression/data_reader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import csv
import time

# https://data.lacity.org/dataset/311-Call-Center-Tracking-Data/ukiu-8trj
#
# crime14_freq = data_reader.read('crimes_2014.csv', 1, '%d-%b-%y %H:%M:%S', 2014)
# freq = read('311.csv', 0, '%m/%d/%Y', 2014)

def read(filename, date_idx, date_parse, year, bucket=7):

days_in_year = 365
bucket = 7

# Create initial frequency map
freq = {}
Expand All @@ -20,8 +19,14 @@ def read(filename, date_idx, date_parse, year, bucket=7):
csvreader = csv.reader(csvfile)
csvreader.next()
for row in csvreader:
if row[date_idx] == '':
continue
t = time.strptime(row[date_idx], date_parse)
if t.tm_year == year and t.tm_yday < (days_in_year-1):
freq[int(t.tm_yday / bucket)] += 1

return freq

if __name__ == '__main__':
freq = read('311.csv', 0, '%m/%d/%Y', 2014)
print freq

0 comments on commit 163c15e

Please sign in to comment.