-
Notifications
You must be signed in to change notification settings - Fork 1
/
Analysis_1.py.html
146 lines (70 loc) · 2.78 KB
/
Analysis_1.py.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
# coding: utf-8
# In[1]:
get_ipython().system('pip install --upgrade pandas')
# In[2]:
#import useful libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
get_ipython().run_line_magic('matplotlib', 'inline')
# In[3]:
#load in the dataset
df_show = pd.read_csv('clean_appointments.csv')
df_show.head()
# In[4]:
df_show.info()
# ## Fix data type issue
# > The dataset has previously been cleaned, but it's data type formatting was lost in converting from a dataframe to CSV, so I'll perform data type transformation on the new dataset
# In[5]:
df_show['patientid'] = df_show['patientid'].astype('str')
type(df_show['patientid'][0])
# In[6]:
df_show['appointmentid'] = df_show['appointmentid'].astype('str')
type(df_show['appointmentid'][0])
# ##### fix problem with scheduled day and appointment day
# In[7]:
#convert feature to datetime for easy manipulation of data
df_show.scheduledday = pd.to_datetime(df_show.scheduledday)
# In[8]:
df_show.appointmentday = pd.to_datetime(df_show.appointmentday)
# ##### convert categorical variables from other types to category
# In[9]:
cat_var = ['gender','scholarship','hipertension',
'diabetes', 'alcoholism', 'handcap',
'sms_received', 'show']
# In[10]:
for val in cat_var:
df_show[val] = df_show[val].astype('category')
# >**Create a mask for the values in the show feature of the df_show dataframe.**
# In[11]:
show = df_show.show == 'Yes'
no_show= df_show.show == 'No'
# ### Analysis 1: How does being on a scholarship affect a patients showing up?
# ##### Graphically
# In[12]:
sns.countplot(x='scholarship', hue='show', data= df_show)
# ##### Statistically
# In[13]:
df_show.scholarship.value_counts()
# ###### The number of persons not on a scholarship is way smaller than that of those on a scholarship
# In[14]:
df_show.groupby('scholarship')['show'].value_counts()
# >*ratio of people on scholarship that showed up* **8283/10861**
# In[15]:
8283/10861
# >*ratio of people not on scholarship that showed up* **79924/99665**
# In[16]:
79924/99665
# ###### From the above
# > It can be seen that the percentage of people not on a scholarship and still showed up for their appointment is slightly higher than their counterparts
# #### Brief conclusion
#
# ###### From tte graphical as well as the statistical analysis, we see that
#
# > About 20,000 persons not on a scholarship didn't show up
#
# > for those on a scholarship, the number of persons not showing up is about 2,500
#
# > Also, we see that scholarship may not be a correct determinant of a patient showing up as there exist a close relationship between the percentages of those that show up and those who didn't show up based on their scholarship positions.