Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed absolute path to ../data #19

Merged
merged 2 commits into from
Jan 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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