Last active
August 29, 2015 14:27
-
-
Save shanemhansen/f36f7c782b1e50f09f1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# Name: module1 | |
# Purpose: | |
# | |
# Author: woswald | |
# | |
# Created: 10/08/2015 | |
# Copyright: (c) woswald 2015 | |
#------------------------------------------------------------------------------- | |
#!/usr/bin/env python | |
import sys | |
import csv | |
# change these | |
inputfile = r"C:\Users\woswald\Desktop\Test_OG.csv" | |
outputfile = r"C:\Users\woswald\Desktop\Test_OG_return.csv" | |
reader = csv.DictReader(open(inputfile)) | |
output = open(outputfile, "w") | |
# for each row get the api and zone then create new field apiZone | |
rows = {} | |
for row in reader: | |
api = row['welldata_API'] | |
zone = row['PROD_ZONE'] | |
apiZone = (api, zone) # this is a "tuple" you are using it as a key | |
if apiZone not in rows: | |
rows[apiZone] = {"OW":0, "GW":0, "oil":0, "gas":0, "water":0} | |
if row['well type'] == 'OW': # replace 'well type' with the correct column name | |
rows[apiZone]["OW"]+=1 | |
else: | |
rows[apiZone]["GW"]+=1 | |
# add oil, gas, water | |
rows[apiZone]['oil']+=row['oil prod'] | |
rows[apiZone]['gas']+=row['oas prod'] | |
rows[apiZone]['water']+=row['water prod'] | |
# print header | |
output.write( "API\tZONE\tAPI_ZONE\n") | |
for apiZone in sorted(rows.keys()): | |
row = rows[apiZone] | |
# print out | |
wellType='unknown' | |
if row['OW'] > row['GW']: | |
wellType = 'oil' | |
elif row['GW'] > row['OW']: | |
wellType = 'gas' | |
elif row['oil'] > row['gas']: | |
wellType = 'oil' | |
elif row['gas'] > row['oil']: | |
wellType = 'gas' | |
output.write("%s\t%s\t%s\n" % (apiZone[0], apiZone[1], wellType)) | |
output.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment