import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import math
df = pd.read_csv(r'C:\Users\cscully\Downloads\Smith vs Jones Patient Types (1).csv')
print(df)
#change data types to float
df.dtypes
df['Strata'] = df['Strata'].astype(float)
df['Previous MI']=df['Previous MI'].astype(float)
df['CHF']=df['CHF'].astype(float)
df['Shock']=df['Shock'].astype(float)
df.dtypes
#Calculate Pattern for Dr Smith and Dr Jones=
expectedOutcome={}
diagnoses={}
for md in ['Smith','Jones']:
#print("Clinician",md)
df1=df[df['Clinician'] == md]
#diagnoses[md]=""
#print(df1['diagnosesStrg'])
#print("df1",df1,df1['LOS'].max())
groupDF = df1.groupby(['Previous MI','CHF','Shock'],as_index=False)
total = 0
for name, group in groupDF:
#print("name",name,"group",group)
tmpDF=pd.DataFrame()
tmpDF=pd.DataFrame(group).reset_index()
maxprob = tmpDF['Prob'].max()
maxlos = tmpDF['LOS'].max()
diagnoses[md,name]=maxlos
val = maxprob*maxlos
#print ("maxprob",maxprob,"maxlos",maxlos,"val",val)
total=total+val
#print("total",total)
expectedOutcome[md]=total
#print("diagnoses",diagnoses)
#print(expectedOutcome)
for item in expectedOutcome:
print(item,"expected LOS: ",expectedOutcome[item])
#Match Clinician and Peer on Common Strata
mdDict={'Jones':'Smith','Smith':'Jones'}
expectedOutcomeNew={}
total=0
for md in ['Smith','Jones']:
#print("Clinician",md)
df1=df[df['Clinician'] == md]
groupDF = df1.groupby(['Previous MI','CHF','Shock'],as_index=False)
total = 0
for name, group in groupDF:
#print("name",name,"group",group)
tmpDF=pd.DataFrame()
tmpDF=pd.DataFrame(group).reset_index()
maxprob = tmpDF['Prob'].max()
#if ','.join([mdDict[md],name]) in diagnoses:
try:
maxlos = diagnoses[mdDict[md],name]
#print("found",mdDict[md],"in diagnoses dictionary")
except:
maxlos = expectedOutcome[md]
#print("did not find")
val = maxprob*maxlos
#print ("maxprob",maxprob,"maxlos",maxlos,"val",val)
total=total+val
#print("total",total)
expectedOutcomeNew[mdDict[md]]=total
print("Expected LOS outcomes for MDs taking care of each others patients: ")
for item in expectedOutcomeNew:
print(item,"expected LOS when taking care of",mdDict[item],
"patients:",expectedOutcomeNew[item])