Created
August 6, 2013 06:06
-
-
Save rsivapr/6162412 to your computer and use it in GitHub Desktop.
run $python problem2.py > avgclaims.csv
This file contains 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
import numpy as np | |
from datetime import date | |
claimsdata = np.genfromtxt('claims.csv', dtype = (int, object, object, int, object), delimiter=',', names = True) | |
poldata = np.genfromtxt('policies.csv', dtype = (int, object, object, object, object), delimiter=',', names = True) | |
f = open('categories') | |
f.readline() | |
dict1 = {} | |
for i in f.readlines(): | |
colorVal = i.split(',') | |
colorVal[1]=colorVal[1][:-1] | |
dict1[colorVal[0]] = colorVal[1] | |
f.close() | |
print "pid, age_at_policy_start, age_at_policy_end, total_number_of_policy_years, overall_avg, red_avg,green_avg, orange_avg" | |
for i in range(poldata.shape[0]): | |
pid = poldata[i][0] | |
codes = {'overall':0, 'red' : 0 , 'green':0, 'orange':0} | |
for j in range(claimsdata.shape[0]): | |
if pid == claimsdata[j][0]: | |
codes[dict1[str(claimsdata[j][3])]] += 1 | |
codes['overall'] += 1 | |
a1 =date(int(poldata[i][1][:4]), int(poldata[i][1][5:7]), int(poldata[i][1][8:10])) | |
a2 =date(int(poldata[i][3][:4]), int(poldata[i][3][5:7]), int(poldata[i][3][8:10])) | |
b1 =date(int(poldata[i][2][:4]), int(poldata[i][2][5:7]), int(poldata[i][2][8:10])) | |
b2 =date(int(poldata[i][3][:4]), int(poldata[i][3][5:7]), int(poldata[i][3][8:10])) | |
as1 = (a1 - a2).days/365.2425 | |
ae1 = (b1 - b2).days/365.2425 | |
n = ae1 - as1 | |
prtstring = str(pid) + "," + str(as1) + "," +str( ae1) + "," + str(n) | |
for i in ['overall', 'red','green','orange']: | |
prtstring += "," + str(codes[i]/n) | |
print prtstring |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment