Skip to content

Commit

Permalink
Merge pull request #19 from bsuman79/master
Browse files Browse the repository at this point in the history
changed absolute path to ../data
  • Loading branch information
derekeder committed Jan 29, 2014
2 parents 73225c8 + 7e8f2ba commit 13d3451
Show file tree
Hide file tree
Showing 6 changed files with 26,307 additions and 5,310 deletions.
59 changes: 49 additions & 10 deletions analysis/analysis.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pandas as pd
import numpy as np
import os



def mwrd(directory='/Users/thoughtworker/chicago-river-sewage/data/', file='mwrd_rain_measurements.csv'):
def mwrd(directory='../data/', file='mwrd_rain_measurements.csv'):
data= pd.read_csv(directory+file, na_values='na')
print data.shape[0]
location= list(set(data.ix[0:,3]))
Expand All @@ -30,19 +30,58 @@ def mwrd(directory='/Users/thoughtworker/chicago-river-sewage/data/', file='mwrd
print data_new.shape
np.savetxt(file, data_new,fmt='%s', delimiter=",")

def clean_water(directory='/Users/thoughtworker/chicago-river-sewage/data/',file='clean-waterway-measurements.csv'):
def clean_water(directory='../data/',file='clean-waterway-measurements.csv'):
data=pd.read_csv(directory+file, na_values='na')
np.savetxt(file, data,fmt='%s', delimiter=",")

def cso():
directory='/Users/thoughtworker/chicago-river-sewage/data/'
cso_file='cso_events_timestamped.csv'
def cso(directory='../data/', file='cso_events_timestamped.csv', file1='ssmma_mwrd_merge_cleanedup.csv'):
readdata= pd.read_csv(directory+file1, na_values='na')
loc=list(readdata['TARP Connection'])
lat=list(readdata['LAT_DEC'])
lng=list(readdata['LON_CONV'])
latitude,longitude={},{}
for key, val in zip(loc, lat):
latitude[key]=val
for key, val in zip(loc,lng):
longitude[key]= val
#print len(latitude), len(longitude)
ct=0
fw=open('jnk.csv','w')
fw1=open('nocoord.csv','w')
with open(directory+file,"r") as f:
for line in f:
lsplit=line.split(",")
if len(lsplit)==4 and "(" not in lsplit[0]:
try:
print>>fw, '%s,%s,%s,%s,%s'%(lsplit[0], lsplit[-2],lsplit[-1], latitude[lsplit[0]],longitude[lsplit[0]])
ct+=1
except KeyError:
print>>fw1, '%s,%s,%s,%s,%s'%(lsplit[0], lsplit[-2],lsplit[-1], 'nan','nan')
ct+=1
if len(lsplit)!=4 and "(" in lsplit[0]:
tmp=line.split("),")[0].split("(")[1].split(",")[0]
try:
print>>fw, '%s,%s,%s,%s,%s'%(tmp,lsplit[-2],lsplit[-1],latitude[tmp],longitude[tmp])
ct+=1
except KeyError:
print>>fw1, '%s,%s,%s,%s,%s'%(tmp,lsplit[-2],lsplit[-1],'nan','nan')
ct+=1
if len(lsplit)!=4 and "(" not in lsplit[0]:
try:
print>>fw, '%s,%s,%s,%s,%s'%(lsplit[0], lsplit[-2],lsplit[-1], latitude[lsplit[0]],longitude[lsplit[0]])
ct+=1
except KeyError:
print>>fw1, '%s,%s,%s,%s,%s'%(lsplit[0], lsplit[-2],lsplit[-1], 'nan','nan')
ct+=1
print ct
fw.close()
os.system('mv jnk.csv '+ file)


cso_data= pd.read_csv(directory+cso_file, na_values='na')
print cso_data.shape



if __name__=="__main__":
mwrd()
#cso()
#clean_water()
cso()
clean_water()
Loading

0 comments on commit 13d3451

Please sign in to comment.