Advertisement

预约挂号后患者实际就诊情况的数据分析

阅读量:

项目:预约挂号后患者实际就诊情况的数据分析

目录

简介

近年来开展的一项便民就医服务就是预约挂号。其主要目的是为了缩短看病流程从而节省患者的等待时间。这种挂号方式不仅帮助患者预先规划就医行程而且有助于医院提升管理效能并提高医疗服务效率同时优化服务质量进而降低潜在的安全隐患。然而由于多种主客观原因导致大部分预约患者无法及时就诊具体情况如下:国内报道显示爽约率在10%至50%之间国外的研究表明爽约率约为3至34 percent这一现象给医疗机构带来了巨大的挑战因为这会导致大量医疗资源闲置进而影响诊疗效率。因此研究这些导致大量医疗资源闲置的因素对于优化资源配置具有重要意义。

本次研究采用了源自kaggle的Medical Appointment No Shows dataset(Medical Appointment No Shows 数据集),其中包含了大约10万条来自巴西地区的预约挂号记录。每条记录都包含了关于患者的多个数值信息,并且对于缺失值采用了以NaN的形式表示的方法进行处理。此外,在该数据集中各列变量的具体含义如下所述:

复制代码
 PatientId:病人Id

    
 AppointmentID: 预约Id
    
 Gender: 性别
    
 ScheduledDay: 预约日期 指患者具体预约就诊的日期
    
 AppointmentDay: 就诊日期 指患者就诊的日期
    
 Age: 年龄
    
 Neighbourhood: 街区 指医院所在位置
    
 Scholarship: 福利保障 说明病人是否是巴西福利项目 Bolsa Família 的保障人群
    
 Hipertension: 高血压
    
 Diabetes:  糖尿病
    
 Alcoholism: 酗酒
    
 Handcap: 残障人士(名称错误)
    
 SMS_received: 接收到短信提醒
    
 No-show: 表示病人是否已如约就诊 “No”表示病人已如约就诊,“Yes”说明病人未前往就诊。
    
    
    
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/mRo824gt3CVsPavGAdDL9XKq7krp.png)

本次研究重点围绕以下几个关键问题展开:

  1. 就诊时间与预定时间间隔缩短的情况下(即缩短至预定时间),患者的就医意愿是否会显著提升?
  2. 是否有数据显示接受福利保障的患者群体具有较高的按期就医率?
  3. 在性别维度上(即男性与女性),患者的就医行为呈现怎样的特征?
  4. 不同年龄段群体(比如青年、中年、老年)在就医行为上是否存在显著差异?
  5. 对接短信服务机制后(即通过短信通知),患者的实际就医表现有何变化?
  6. 在疾病类别维度上(比如普通疾病 vs 严重疾病),患者的就医响应有何差异?
复制代码
 # 导入包

    
 import pandas as pd
    
 import numpy as np
    
 import matplotlib.pyplot as plt
    
 import seaborn as sns
    
 %matplotlib inline
    
    
    
    
    python

数据整理

评估数据

复制代码
 # 加载数据并打印几行。

    
 df = pd.read_csv('noshowappointments-kagglev2-may-2016.csv')
    
 df.head()
    
    
    
    
    python

Out[2]:

PatientId AppointmentID Gender ScheduledDay AppointmentDay Age Neighbourhood Scholarship Hipertension Diabetes Alcoholism Handcap SMS_received No-show
0 2.990000e+13 5642903 F 2016-04-29T18:38:08Z 2016-04-29T00:00:00Z 62 JARDIM DA PENHA 0 1 0 0 0 0 No
1 5.590000e+14 5642503 M 2016-04-29T16:08:27Z 2016-04-29T00:00:00Z 56 JARDIM DA PENHA 0 0 0 0 0 0 No
2 4.260000e+12 5642549 F 2016-04-29T16:19:04Z 2016-04-29T00:00:00Z 62 MATA DA PRAIA 0 0 0 0 0 0 No
3 8.680000e+11 5642828 F 2016-04-29T17:29:31Z 2016-04-29T00:00:00Z 8 PONTAL DE CAMBURI 0 0 0 0 0 0 No
4 8.840000e+12 5642494 F 2016-04-29T16:07:23Z 2016-04-29T00:00:00Z 56 JARDIM DA PENHA 0 1 1 0 0 0 No
复制代码
 #检查数据形状

    
 df.shape
    
  
    
 #检查数据类型,以及是否有缺失数据或错误数据的情况。
    
 df.info()
    
  
    
 #重复行数
    
 sum(df.duplicated())
    
  
    
 #缺失值行数
    
 df.isnull().any(axis = 1).sum()
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/oFHY0OSITB2QkvDeJjGluhspMPnb.png)
复制代码
 #age的唯一值

    
 df.Age.unique()
    
    
    
    
    python

Out[7]:

复制代码
 array([ 62,  56,   8,  76,  23,  39,  21,  19,  30,  29,  22,  28,  54,

    
     15,  50,  40,  46,   4,  13,  65,  45,  51,  32,  12,  61,  38,
    
     79,  18,  63,  64,  85,  59,  55,  71,  49,  78,  31,  58,  27,
    
      6,   2,  11,   7,   0,   3,   1,  69,  68,  60,  67,  36,  10,
    
     35,  20,  26,  34,  33,  16,  42,   5,  47,  17,  41,  44,  37,
    
     24,  66,  77,  81,  70,  53,  75,  73,  52,  74,  43,  89,  57,
    
     14,   9,  48,  83,  72,  25,  80,  87,  88,  84,  82,  90,  94,
    
     86,  91,  98,  92,  96,  93,  95,  97, 102, 115, 100,  99,  -1],
    
       dtype=int64)
    
    
    
    
    html
  • 数据集没有缺失值,这对后面的分析来说是个大大的好消息。

数据清理

在评估数据时,发现数据集的"Handcap"列标签书写错误,为了保持列名的一致,将"No-show"列中的分隔符改成下划线。 同时"ScheduledDay"列和"AppointmentDay"列都是时间列,应该将其转化成datetime数据类型。 观察到"Age"列的唯一值中有-1,应该将其清除掉,同时为了便于分析,对"Age"列进行拆分,分成不同年龄段。

重命名列

为了与'PatientId'列名保持一致将'AppointmentID'改成'AppointmentId',数据集中的"Handcap"列标签书写错误,将其改成"Handicap",重命名"No-show"列标签将"-"替换为"_"。

时间化数据

使用 pandas 的 to_datetime() 方法来将数据集中的"ScheduledDay"列和"AppointmentDay"列转换为datetime 数据类型,同时计算时间间隔。

拆分年龄

Pandas 的 cut 函数可以让你将数据"切分"为组。利用pd.cut()将年纪拆分成不同的年龄段。其中06岁为儿童(childhood),717岁为少年(juvenile),1840岁为青年(youth),41岁65岁为中老年(middle_aged),66岁以上为老年人(elderly)

复制代码
 #重命名列名

    
 df.rename(columns = {'AppointmentID':'AppointmentId',
    
                  'Handcap':'Handicap',
    
                  'No-show':'No_show'},inplace = True)
    
    
    
    
    python
复制代码
 #时间化数据

    
 df['ScheduledDay'] = pd.to_datetime(df['ScheduledDay'])
    
 df['AppointmentDay'] = pd.to_datetime(df['AppointmentDay'])
    
 ​
    
 #计算时间间隔
    
 df['WaitingTime'] = df['AppointmentDay'] - df['ScheduledDay']
    
 ​
    
 #WaitingTime列取天数,当天为-1,0
    
 df['WaitingTime']= df['WaitingTime'].apply(lambda x: x.days)
    
  
    
 #过滤数据
    
 df = df[df['WaitingTime']>=-1]
    
  
    
 df.WaitingTime.describe()
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/sxOIyzFoXQ3BVqJtwvZTUj61Y7bM.png)

Out[10]:

复制代码
 count    110522.000000

    
 mean          9.184253
    
 std          15.255115
    
 min          -1.000000
    
 25%          -1.000000
    
 50%           3.000000
    
 75%          14.000000
    
 max         178.000000
    
 Name: WaitingTime, dtype: float64
    
    
    
    
    html
复制代码
 #时间标签

    
 time_names = ['Sameday','OneDay','OneWeek','TwoWeek','ThreeWeek','OneMonth']
    
 #把数据“分割”成组的边缘列表
    
 time_edges = [-2,0,1,7,13,18,179]
    
 ​
    
 # 创建 WaitingDays 列
    
 df['WaitingDays'] = pd.cut(df['WaitingTime'], time_edges, labels=time_names)
    
 ​
    
 # 显示数据框的前几行,确认更改
    
 df.head()
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/qC20KSE4DmcGjF8ypV5wMdLuTlrf.png)

Out[11]:

PatientId AppointmentId Gender ScheduledDay AppointmentDay Age Neighbourhood Scholarship Hipertension Diabetes Alcoholism Handicap SMS_received No_show WaitingTime WaitingDays
0 2.990000e+13 5642903 F 2016-04-29 18:38:08 2016-04-29 62 JARDIM DA PENHA 0 1 0 0 0 0 No -1 Sameday
1 5.590000e+14 5642503 M 2016-04-29 16:08:27 2016-04-29 56 JARDIM DA PENHA 0 0 0 0 0 0 No -1 Sameday
2 4.260000e+12 5642549 F 2016-04-29 16:19:04 2016-04-29 62 MATA DA PRAIA 0 0 0 0 0 0 No -1 Sameday
3 8.680000e+11 5642828 F 2016-04-29 17:29:31 2016-04-29 8 PONTAL DE CAMBURI 0 0 0 0 0 0 No -1 Sameday
4 8.840000e+12 5642494 F 2016-04-29 16:07:23 2016-04-29 56 JARDIM DA PENHA 0 1 1 0 0 0 No -1 Sameday
复制代码
 # 确定数据类型

    
 df.info()
    
    
    
    
    python
复制代码
 #清除年龄异常值

    
 df = df[df['Age']>=0]
    
 ​
    
 #将'Age'列拆分成不同年龄段
    
 #时间标签
    
 age_names = ['childhood','juvenile','youth','middle_aged','elderly']
    
 #把数据“分割”成组的边缘列表
    
 age_edges = [0,6,17,40,65,179]
    
 ​
    
 # 创建 Generation 列
    
 df['Generation'] = pd.cut(df['Age'], age_edges, labels=age_names)
    
  
    
 # 显示数据框的前几行,确认更改
    
 df.head()
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/f09gRIuKLnptlCFwemj4aXP32QAd.png)

​Out[13]:

PatientId AppointmentId Gender ScheduledDay AppointmentDay Age Neighbourhood Scholarship Hipertension Diabetes Alcoholism Handicap SMS_received No_show WaitingTime WaitingDays Generation
0 2.990000e+13 5642903 F 2016-04-29 18:38:08 2016-04-29 62 JARDIM DA PENHA 0 1 0 0 0 0 No -1 Sameday middle_aged
1 5.590000e+14 5642503 M 2016-04-29 16:08:27 2016-04-29 56 JARDIM DA PENHA 0 0 0 0 0 0 No -1 Sameday middle_aged
2 4.260000e+12 5642549 F 2016-04-29 16:19:04 2016-04-29 62 MATA DA PRAIA 0 0 0 0 0 0 No -1 Sameday middle_aged
3 8.680000e+11 5642828 F 2016-04-29 17:29:31 2016-04-29 8 PONTAL DE CAMBURI 0 0 0 0 0 0 No -1 Sameday juvenile
4 8.840000e+12 5642494 F 2016-04-29 16:07:23 2016-04-29 56 JARDIM DA PENHA 0 1 1 0 0 0 No -1 Sameday middle_aged

探索性数据分析

1、就诊时间与预定时间间隔越短,如约就诊的可能性就越高么?

复制代码
 #绘图函数

    
 def CP_plot(df,index,df_P,key=''):
    
     fig, ax1 = plt.subplots(figsize=(8,5))
    
     df.plot(kind = 'bar',rot=0,ax=ax1)
    
     # 标题和标签
    
     plt.ylabel('Counts',fontsize = 14)
    
     plt.xlabel('{:s}'.format(key),fontsize = 14)
    
     plt.title('Probability of the {:s}'.format(key),fontsize = 14)
    
 ​
    
     ax2 = ax1.twinx()  #plt second data set using second(right) axis
    
     ax2.set_ylim([0, 0.5])
    
     #plt.plot(['0','1'],[No_SMS_received_P,SMS_received_P],'r>-')
    
     sns.pointplot(x=index, y=df_P, color='r', ax=ax2)
    
     plt.ylabel('Probability',fontsize = 14)
    
     return None
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/nH47ySK3Ti8o62DC5WxRYFA1Itmu.png)
复制代码
 #计算不同的时间间隔,如约就诊的可能性

    
 WaitingDays_Count = df.query('No_show == "Yes"').WaitingDays.value_counts(sort=False)
    
 No_WaitingDays_Count = df.query('No_show == "No"').WaitingDays.value_counts(sort=False)
    
 df_1 = pd.DataFrame({'Yes':WaitingDays_Count,'No':No_WaitingDays_Count})
    
 ​
    
 ​
    
 WaitingDays_P = df.query('No_show == "Yes"').WaitingDays.value_counts(sort=False)/df['WaitingDays'].value_counts(sort=False)
    
 ​
    
 #绘图
    
 CP_plot(df_1,WaitingDays_P.index, WaitingDays_P,key='WaitingDays')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/OsPh3Xm8x1tEeudD6pc4Yoq79TC0.png)
复制代码
    df.groupby('WaitingDays')['No_show'].value_counts()
复制代码
 WaitingDays  No_show

    
 Sameday      No         40870
    
          Yes         2905
    
 OneDay       No          5123
    
          Yes         1602
    
 OneWeek      No         16852
    
          Yes         5727
    
 TwoWeek      No          6699
    
          Yes         2994
    
 ThreeWeek    No          3948
    
          Yes         1878
    
 OneMonth     No         14715
    
          Yes         7208
    
 Name: No_show, dtype: int64
    
    
    
    
    html
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/ruTkcIFXp84wevablQmJExK159B7.png)
复制代码
    df.groupby('WaitingDays')['No_show'].value_counts().unstack()
复制代码
 #WaitingDays_P = df.query('No_show == "Yes"').WaitingDays.value_counts(sort=False)/df['WaitingDays'].value_counts(sort=False)

    
 fig,ax1 = plt.subplots(figsize = (8,5))
    
  
    
 df.groupby('WaitingDays')['No_show'].value_counts().unstack().plot(kind='bar',rot=0,ax=ax1)
    
 plt.ylabel('Count',fontsize = 14)
    
  
    
 ax2 = ax1.twinx()  #plt second data set using second(right) axis
    
 ax2.set_ylim([0, 0.5])    
    
 sns.pointplot(x=WaitingDays_P.index, y=WaitingDays_P, color='r', ax=ax2)
    
 plt.ylabel('Probability',fontsize = 14)
    
 plt.title('Probability of the WaitingDays',fontsize = 14)
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/9021UNGLfhFR6cgQBCXAqws5YZW8.png)

当日预约即日就诊的人数最多;
当预约时间和就诊时间间隔较短时(即两者相近),如约就诊的概率增大;而当间隔较长时,则会增加爽约频率。

2、享受福利待遇的患者如约就诊率较高吗?

复制代码
  #计算福利待遇患者如约就诊率

    
 Scholarship_Count = df.query('No_show == "Yes"').Scholarship.value_counts()
    
 No_Scholarship_Count = df.query('No_show == "No"').Scholarship.value_counts()
    
 df_2 = pd.DataFrame({'Yes':Scholarship_Count,'No':No_Scholarship_Count})
    
 ​
    
 Scholarship_P = (df.query('Scholarship == 1')['No_show'] == "Yes").mean()
    
 No_Scholarship_P = (df.query('Scholarship == 0')['No_show'] == "Yes").mean()
    
  
    
 #绘图
    
 CP_plot(df_2,['0','1'],[No_Scholarship_P,Scholarship_P],key='Scholarship')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/xm0hf81LD3eKMqdZacWUTNIklXV2.png)

可观察到接受有福利保障的患者,在按时就医方面表现不如未享受相关保障者的 counterpart, 这表明现有福利措施未能有效提升患者的就医率。

3、不同性别、年龄段的患者如约就诊的情况如何?

A.不同性别的患者如约就诊率如何?

复制代码
  #计算不同性别的患者如约就诊率

    
 Gender_Count = df.query('No_show == "Yes"').Gender.value_counts()
    
 No_Gender_Count = df.query('No_show == "No"').Gender.value_counts()
    
 df_3 = pd.DataFrame({'Yes':Gender_Count,'No':No_Gender_Count})
    
 ​
    
 Female_Yes = (df.query('Gender == "F"')['No_show'] == "Yes").mean()
    
 Male_Yes = (df.query('Gender == "M"')['No_show'] == "Yes").mean()
    
 ​
    
 #绘图
    
 CP_plot(df_3,['Female','Male'],[Female_Yes,Male_Yes],key='Gender')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/nUQK9fEdilWYhGAj67xLmM18rtu0.png)
  • 男性患者如约就诊的可能性比女性患者略低一点。

B.不同年龄段的患者如约就诊率如何?

复制代码
 #计算不同年龄段的患者如约就诊率

    
 Generation_Count = df.query('No_show == "Yes"').Generation.value_counts(sort=False)
    
 No_Generation_Count = df.query('No_show == "No"').Generation.value_counts(sort=False)
    
 df_4 = pd.DataFrame({'Yes':Generation_Count,'No':No_Generation_Count})
    
 ​
    
 Generation_P = df.query('No_show == "Yes"').Generation.value_counts(sort=False)/df['Generation'].value_counts(sort=False)
    
 #No_WaitingDays_P = df.query('No_show == "No"').WaitingDays.value_counts(sort=False)/df['WaitingDays'].value_counts(sort=False)
    
 ​
    
 #绘图
    
 CP_plot(df_4,Generation_P.index, Generation_P,key='Generation')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/G7PTjrolUZfHp2xik6Sm0RNQXt5b.png)
  • 老年人群中约诊人数最多;
  • 65岁以上老年人群的正常就医概率最高,在校学生群体的正常就医比例最低。

C.不同性别、年龄段的患者如约就诊的情况如何?

复制代码
 #计算不同性别,每个年龄段如约就诊的数量

    
 female_counts = df.query('Gender == "F"').groupby(['No_show','Generation'])['Age'].count()
    
 male_counts = df.query('Gender == "M"').groupby(['No_show','Generation'])['Age'].count()
    
  
    
 #计算男性患者的每个年龄段的如约就诊率和爽约率
    
 Female_Yes = female_counts['Yes']/df.query('Gender == "F"').groupby(['Generation'])['Age'].count()
    
 Male_Yes = male_counts['Yes']/df.query('Gender == "M"').groupby(['Generation'])['Age'].count()
    
 df_111 = pd.DataFrame({'F':Female_Yes,'M':Male_Yes})
    
 ​
    
 #绘图
    
 df_111.plot(figsize=(8,5),style = 'o-')
    
 # 标题和标签
    
 plt.ylabel('Probability',fontsize = 14)
    
 plt.xlabel('Generation',fontsize = 14)
    
 labels = ['childhood', 'juvenile', 'youth', 'middle_aged', 'elderly']  # x 坐标刻度标签
    
 plt.xticks(np.arange(len(Female_Yes)),labels)
    
 plt.title('Probability of the Generation and Gender',fontsize = 14);
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/G6SzWwvVds5rDoKuPnC4ZHikfhNm.png)

男性患者和女性患者,少年爽约率均最高,老年爽约率均最低。

复制代码
 #获取女性每个年龄段等级数量

    
 female_counts = df.query('Gender == "F"').groupby(['No_show','Generation'])['Age'].count()
    
 Female_No = female_counts['No']
    
 Female_Yes = female_counts['Yes']
    
 ​
    
 #获取男性每个年龄段等级数量
    
 male_counts = df.query('Gender == "M"').groupby(['No_show','Generation'])['Age'].count()
    
 Male_No = male_counts['No']
    
 Male_Yes = male_counts['Yes']
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/y3SgfKVRH0Om7It2zxAJGue1B5Ms.png)
复制代码
 #绘制不同性别每个年龄段的如约就诊人数图

    
 fig, ax = plt.subplots(figsize = (15,5))
    
 ind = np.arange(len(Female_No))  # 组的 x 坐标位置
    
 width = 0.35  
    
 ​
    
 plt.subplot(1, 2, 1)
    
 # 绘制条柱
    
 No_bars = plt.bar(ind, Female_No, width, color='r', alpha=.7, label='No')
    
 Yes_bars = plt.bar(ind + width, Female_Yes, width, color='b', alpha=.7, label='Yes')
    
 ​
    
 # 标题和标签
    
 plt.ylabel('Counts')
    
 plt.xlabel('Generation')
    
 plt.title('Female')
    
 locations = ind + width / 2  # x 坐标刻度位置
    
 labels = ['childhood', 'juvenile', 'youth', 'middle_aged', 'elderly']  # x 坐标刻度标签
    
 plt.xticks(locations, labels)
    
 #plt.axhline(y=Male_No,color = 'g',linewidth = 0.5);
    
 ​
    
 # 图例
    
 plt.legend();
    
 ​
    
 plt.subplot(1, 2, 2)
    
 # 绘制条柱
    
 No_bars = plt.bar(ind, Male_No, width, color='r', alpha=.7, label='No')
    
 Yes_bars = plt.bar(ind + width, Male_Yes, width, color='b', alpha=.7, label='Yes')
    
 ​
    
 ​
    
 # 标题和标签
    
 plt.ylabel('Counts')
    
 plt.xlabel('Generation')
    
 plt.title('Male')
    
 locations = ind + width / 2  # x 坐标刻度位置
    
 labels = ['childhood', 'juvenile', 'youth', 'middle_aged', 'elderly']  # x 坐标刻度标签
    
 plt.xticks(locations, labels)
    
 #plt.axhline(y=Male_No,color = 'g',linewidth = 0.5);
    
 ​
    
 # 图例
    
 plt.legend();
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/pZRQ4jtUPz5qwITSar2mdWlFbfoJ.png)
  • 女性患者中处于40~65岁之间的群体具有最高的定期就医比例;处于0~6岁之间的群体则显示出最低水平的定期就医比例以及较高的爽约为症状。

  • 男性患者群体中处于40~65岁之间的个体拥有最高的定期就医比例;而超过65岁的人群则呈现出最低水平的定期就医比例以及较高的爽约为症状;

  • 男性及女性患者的定期就医率最高水平都出现在年龄层超过65岁时。

5、接收到短信提醒的患者如约就诊率如何?

复制代码
 #计算接收到短信提醒的患者如约就诊率

    
 SMS_received_Count = df.query('No_show == "Yes"').SMS_received.value_counts(sort=False)
    
 No_SMS_received_Count = df.query('No_show == "No"').SMS_received.value_counts(sort=False)
    
 df_s = pd.DataFrame({'Yes':SMS_received_Count,'No':No_SMS_received_Count})
    
 ​
    
 SMS_received_P = (df.query('SMS_received == 1')['No_show'] == "Yes").mean()
    
 No_SMS_received_P = (df.query('SMS_received == 0')['No_show'] == "Yes").mean()
    
 ​
    
 #绘图
    
 CP_plot(df_s,['0','1'],[No_SMS_received_P,SMS_received_P],key='SMS_received')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/Ai6ut9EGcTmZ21zaXjWnL8FKV7lh.png)

数据显示接受短信提醒的患者按时就诊率低于未接受短信提醒的患者, 即短信提醒功能未能提高患者的按时就诊率.

6、不同种类病患者如约就诊率如何?

A.不同疾病的年龄分布状况

复制代码
 #设置背景及标题

    
 sns.set_style('dark')
    
 ​
    
 f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15, 4), sharex=True)
    
 f.suptitle('Age distribution of different types of Diseases')
    
 ​
    
 #作图
    
 sns.distplot(df.query('Hipertension == 1')['Age'],ax=ax1)
    
 sns.distplot(df.query('Diabetes == 1')['Age'],color='g',ax=ax2)
    
 sns.distplot(df.query('Alcoholism == 1')['Age'],color='r',ax=ax3)
    
 ax1.legend('Hipertension')
    
 ax2.legend('Diabetes')
    
 ax3.legend('Alcoholism');
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/rVGCjp0x3EPvOdA4BtYQkyf6WiKq.png)
复制代码
 #不同疾病,不同年龄段的患者数量

    
 m = df.groupby('Generation').sum()
    
 ​
    
 #设置背景及标题
    
 sns.set_style('dark')
    
 ​
    
 f, ax = plt.subplots(1, 3, figsize=(15, 4), sharex=True)
    
 f.suptitle('Generation distribution of different types of Diseases')
    
 ​
    
 #作图
    
 ​
    
 plt.subplot(131)
    
 m.Hipertension.plot(kind = 'pie',autopct='%.0f%%')
    
 ​
    
 plt.subplot(132)
    
 m.Diabetes.plot(kind = 'pie',autopct='%.0f%%')
    
 ​
    
 plt.subplot(133)
    
 m.Alcoholism.plot(kind = 'pie',autopct='%.0f%%')
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/qaE6MP49dbxhcJsnHtfNG2VvKI8l.png)

数据显示,高血压、糖尿病患者的年龄分布主要集中在50至70岁之间,而醺酒患者的年龄分布则集中在50岁左右。

按年龄段细分,三种疾病在儿童及少年期的患病人数最少,而在中老年群体中患病人数达到最多水平。

从年龄层面上看,青少年及成人期这三个疾病的主要患病群体较为分散,而老年人群则是各类疾病的高发区。

B.不同疾病的如约就诊率

复制代码
 #计算不同年龄段如约就诊的概率

    
 m1 = df.query('No_show == "Yes"').groupby('Generation').sum()/df.groupby('Generation').sum()
    
 ​
    
 #绘图
    
 #设置背景及标题
    
 sns.set_style('dark')
    
 ​
    
 f, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(6, 6), sharex=True)
    
 f.suptitle('Age distribution of different types of Diseases')
    
 ​
    
 #作图
    
 sns.pointplot(m1.index,m1.Hipertension,ax=ax1)
    
 sns.pointplot(m1.index,m1.Diabetes,color='g',ax=ax2)
    
 sns.pointplot(m1.index,m1.Alcoholism,color='r',ax=ax3);
    
    
    
    
    python
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-12/PpwBtgTheF0rEa4LUSMNvICVz7Yf.png)
复制代码

可以看出高血压和糖尿病这两种疾病中,在青少年群体中存在较高的就医率,在其中醉酒患者就医率最高的为青少年群体。但对于这三类病症而言由于青少年群体的样本数量不足这一结果不具备实际应用价值。从其他年龄段来看我们能够了解到各种疾病患者的年龄越大其依从性较强的可能性更高

结论

通过上面的分析,我们可以得出的结论如下:

当诊断时间和预定时间间隔缩短时(即两者之间的时间间隔越短),患者的按期就医可能性显著提升;同样地,在当天预约的情况下也是如此。

尽管享受福利待遇以及短信提醒服务的存在,并未显著提高患者的按期就医比例(即利用率)。

从性别角度来看(即从男女性别两个维度进行分析),患者的按期就医比例差异并不明显(即差距不大)。

老年人群中以65岁以上人群最为重视按时就医;而青少年群体则普遍缺乏这一意识(即重视程度较低)。

在40至65岁的女性群体中(即年龄处于此区间内的女性),按期就医的人数达到最高;而在0至6岁的小儿中,则既是最低也是最少(即数量最少)。

说明

本次研究采用的是巴西预约挂号系统收集的求诊记录。基于当前的数据仅来自一个国家,在推广至其他国家时需谨慎考虑。

超好用的 pandas 之 groupby:https://www.jianshu.com/p/42f1d2909bb6

全部评论 (0)

还没有任何评论哟~