Arrival time

The arrival time is another visit information variable included in the data. However, in its raw form, it will probably be unhelpful, since it can be an integer between 0 and 2,359. Let's make a NIGHT variable that is only positive when the patient comes in between 8 PM and 8 AM. Our reasoning behind creating this variable is the hypothesis that patients arriving at the ED outside of regular hours have more serious illnesses and will, therefore, be admitted more often to the hospital. We can use the following code to make the NIGHT variable:

def is_night(arrtime):
arrtime_int = int(arrtime)
if ((arrtime_int >= 0) & (arrtime_int < 800)):
return 1
elif ((arrtime_int >= 2000) & (arrtime_int < 2400)):
return 1
else:
return 0

X_train.loc[:,'NIGHT'] = df_ed.loc[:,'ARRTIME'].apply(is_night)
X_test.loc[:,'NIGHT'] = df_ed.loc[:,'ARRTIME'].apply(is_night)

X_train.drop('ARRTIME', axis=1, inplace=True)
X_test.drop('ARRTIME', axis=1, inplace=True)

In the preceding example, we first code a function that returns 1 if the patient has arrived between 8 PM and 8 AM, and returns 0 otherwise. We then use the apply() function of pandas to "apply" this function to the ARRTIME column and make the NIGHT column. We then drop the original ARRTIME column since it is not useful in its raw form.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset