application_vnd.jupyter.stderr_output_1.png
import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

raw_data = pd.read_csv('../input/rows.csv', usecols=['CMPLNT_FR_DT', 'Latitude', 'Longitude']).dropna()

first_date = np.datetime64('2006-01-01')
days = (pd.to_datetime(raw_data['CMPLNT_FR_DT'], format='%m/%d/%Y', errors='coerce') - first_date).dt.days
days

days_ = days[days.isnull() == False]
days_ = days_[days_ > 0]
days_ = days_
days_

rd = raw_data
rd = rd[rd['Latitude'] > rd['Latitude'].mean() - 3 * rd['Latitude'].std()][rd['Latitude'] < rd['Latitude'].mean() + 3 * rd['Latitude'].std()]
rd = rd[rd['Longitude'] > rd['Longitude'].mean() - 3 * rd['Longitude'].std()][rd['Longitude'] < rd['Longitude'].mean() + 3 * rd['Longitude'].std()]

rd.shape

GRID_X_DIM = 120
GRID_Y_DIM = 100
lng_step = (max_lng - min_lng) / (GRID_X_DIM - 1)
lat_step = (max_lat - min_lat) / (GRID_Y_DIM - 1)
(lng_step, lat_step)

def to_grid(lat, lng):
    x = (lng - min_lng) // lng_step
    y = (lat - min_lat) // lat_step
    return x + GRID_X_DIM * y

data = pd.DataFrame(rd['CMPLNT_FR_DT'])
data['Days'] = days_
data['Grid'] = to_grid(rd['Latitude'], rd['Longitude'])
data = data.dropna()
data['Days'] = data['Days'].astype('int32')
data['Grid'] = data['Grid'].astype('int32')
data