Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

O: This function needs to be completed. Suggested steps: 1. Create list of normal patients (hf_events.csv only contains information about heart

O: This function needs to be completed.

   Suggested steps:
       1. Create list of normal patients (hf_events.csv only contains information about heart failure patients).
       2. Split events into two groups based on whether the patient has heart failure or not.
       3. Calculate index vid for each patient.

   IMPORTANT:
       `indx_vid` should be a pd dataframe with header `['pid', 'indx_vid']`.
   '''
     

   hf_patients = events.loc[events.pid.isin(hf)]
   

   norm_patients = events.loc[~events.pid.isin(hf)]
   norm_patients= norm_patients.sort_values(by=['pid', 'vid'])

   vidcount_norm = (norm_patients.groupby("pid")["vid"].max())
   print(len(vidcount_norm))
 
   vidcount_hf = (hf_patients.groupby("pid")["vid"].min())
   print(len(vidcount_hf))
 
   
   #vidcount_hf[50285]=3
   #print(vidcount_hf[50285])
   #print(vidcount_hf[98085]) #=5

   #print(vidcount_norm[20853])#=1
   #print(vidcount_norm[47877]) #=1
 
   
   f1 = pd.DataFrame({'pid':vidcount_norm.index, 'indx_vid':vidcount_norm.values})
   f2 = pd.DataFrame({'pid':vidcount_hf.index, 'indx_vid':vidcount_hf.values})
   f4 = dict(list(zip(f2.pid, f2.indx_vid)))
   #print(f4)
   f3 = pd.concat([f1, f2], axis=0)
   f3 = f3.sort_values(by=['pid'])
 
   #f4 = pd.DataFrame({'pid':f3.index, 'indx_vid':f3.values})
   
   indx_vid = f3
   print(indx_vid.shape)
   print(f3[f3.pid == 78])
   print(f3[f3.pid == 1230])
   #print(indx_vid)  
   #indx_vid1 = dict(list(zip(indx_vid_df.pid, indx_vid_df.indx_vid)))
   #print(indx_vid1)
   # your code here
   #raise NotImplementedError
   
   return indx_vid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

from collections import defaultdict import pandas as pd def cal... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

More Books

Students also viewed these Programming questions