Data Stories: Medical Appointment Attendance in Brazil
Tags: datascience, python
Published: 2022-06-03 12:18:55

Welcome to **Data Stories**, this is a series where we will explore various data and deduce insights. We shall listen to the data as it tells us its story.

We shall begin with a story about medical appointment attendance in Brazil. The data hails from [Kaggle](https://www.kaggle.com/datasets/joniarroba/noshowappointments) and we shall explore it to find out whether or not Brazilians attend their medical appointments.

_Side Note:_ This project was part of the Udacity Data Analytics Nanodegree and why not share it with fellow techies.

**Table of Contents**

- [Introduction](#Introduction:Dataset Description)
- [Questions For Analysis](#Questions For Analysis)
- [Data Wrangling](#Data Wrangling)
- [Data Cleaning](#Data Cleaning)
- [Exploratory Data Analysis](#Exploratory Data Analysis)
- [Conclusions](#Conclusions)

**Introduction: Dataset Description**
The no-show appointments dataset is a collection of 100,000 medical appointments made by Brazilian patients who did not show up. It aims to help us figure out why they don't show up for their doctor's visits. There is enough data to tell a story about why people don't show up and to help mitigate this problem. This will aid in answering questions in the analysis portion and overcoming issues such as poor patient management.

**Questions For Analysis**
The following are some of the questions that we seek to answer from the analysis of this dataset:

1. How is the attendance to the appointments by the patients?
2. What is the relationship between the independent variables and the dependent variable?
3. What is the attendance of the patients on the Scholarship program to their medical appointments?

**Data Wrangling**
In this section the data is loaded into the notebook and we'll review it to see if there are any errors, which we'll address in the Data Cleaning section.

We begin by importing the necessary libraries.
```
#Import statements for all of the packages that are used.

import pandas as pd

import numpy as np

import seaborn as sns

import matplotlib.pyplot as plt

%matplotlib inline
```


**Data Wrangling**
During the wrangling process there are few problems noticed with the dataset and they include:

![We begin by loading and inspecting the dataset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2emkc20vj2h5gltwpycz.png)

![We check the information about the dataset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urt06hol6apns98bv5js.png)


![Checking for missing data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rph1prg594c95xyp9izr.png)


![Looking for duplicated data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ure23pfbigjha7cqujfr.png)


![Checking for the number of unique values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/coymkvbq1hxsp7hjihn6.png)


![Checking the datatypes of the column values](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufbbr2mtav8cfxit99ya.png)


**Data Cleaning**
The column names Hipertension and Handicap and are misspelled while SMS_ received doesn't require the underscore also No-show does not need the - sign.

The Patient ID and Appointment ID columns are not relevant to this analysis.

The datatypes of Scheduled day and Appointment day are incorrect. They are objects which is incorrect because they are dates which should be date datatypes.

In this Data Cleaning section we shall make corrections to aforementioned problems.


![Renaming the column to Hypertension](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9otaov7ycrtwao2lcxwx.png)

![Renaming the column to Handicap](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sduyc64v3ij28c6v8r6.png)

![Renaming the SMS received column](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ac7nozver7r84yyhnjqy.png)


![Changing the datatype of the Scheduled day column](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnb1k6py0l185pvmp6qh.png)

![Changing the datatype of the Appointment day column](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkii8zu7i5si3pnftqd2.png)

![Dropping columns we do not require](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2p8rlw98d10hqpgvspz.png)

![The final clean dataset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5cmafk0eoqda3v3jk1g2.png)
**Exploratory Data Analysis**
The data is clean and ready for exploration. Here statistics shall be used to address the questions in the Introduction part and visualizations will also be created to answer the questions.

![Answering the first analysis question](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zciqj0obwalw7px0b7lg.png)

![Pie chart showing the attendance of patients](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5rvcm4faj7vihh6921r.png)

![Answering the second analysis question](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adyaxzwtqdg6fnttxbi0.png)

![Answering the second analysis question](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uokd7xj78n1dki8ny691.png)

![Answering the second analysis question](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pt192byypovp408j9j5.png)


![Bar plots showing independent variables against the dependent variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzauhfeuh3b9d5cpyw7b.png)

![Bar plots showing independent variables against the dependent variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6reib3gkkz548pf5qwsl.png)


The important details from the visualizations are as follows:

Gender - there is a stark difference between males and females in terms of attendance to their medical appointments. The visualization show fewer males are attending their appointments compared to the females.

SMS received - there is a large difference in the people who do receive SMS reminders for the appointments. A large number of those who receive the text do not show up to their appointments.

Diabetes - there is a dismal trend in the patients who have Diabetes. The visualization shows they attend their appointments the least compared to those without the disease.

Hypertension - there is a dismal trend in the patients who have Hypertension. The visualization shows they attend their appointments the least compared to those without the disease.


![Answering the third analysis question](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msbityrexbq6xl8erhso.png)

![Pie chart showing the attendance of patients on the Scholarship program](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f29svpx7lpduyfaw8kvm.png)


**Conclusions**
In this section a detailed summary of the research is provide in relation to the questions posed in the Introduction section.

From the study of 100,000 medical appointments by patients in Brazil we can draw the general conclusion that most of them do not attend their scheduled appointments. This is a sad state of affairs as medical appointments are very useful in early detection of diseases and also management of patients' conditions.

**_How is the attendance to the appointments by the patients?_**
The attendance of patients to their medical appointments is poor as only 20% of them attend their appointments that they schedule. 80% of patients fail to attend their appointments and this poses a challenge of management of their conditions such as Diabetes and Hypertension. This may have a domino effect of symptoms getting worse and even early deaths when this could be prevented by the patients attending their appointments.

**_What is the relationships between the independent variables and the dependent variable?_** 
In terms of **Gender**, there is a difference between males and females in terms of attendance to their medical appointments with fewer males are attending their appointments compared to the females.
In terms of **SMS received**, there is a large difference in the people who do receive SMS reminders for the appointments with a greater number of those who receive the text not showing up to their appointments.

In terms of **Diabetes**, there is a dismal trend in the patients who have Diabetes, they attend their appointments the least compared to those without the disease.

In terms of **Hypertension**, there is a dismal trend in the patients who have Hypertension, they attend their appointments the least compared to those without the disease.

**_What is the attendance of the patients on the Scholarship program to their medical appointments?_** 
The attendance of patients on the Scholarship program is poor with only 10% of them attending their scheduled appointments while an astounding 90% do not. This was a special feature to study because the Scholarship program dubbed Bolsa Familia is a welfare program intended to assist families in Brazil by providing them with an allowance, this move as made to assist them in part with their medical expenses. However, as the study shows this is not the case. This situation needs to be looked into by the government and measures put in place to ensure the program works for the people of Brazil and also they should be encouraged to attend their medical appointments.

_Limitations in the research_

There may be more factors around the reasons Brazilian citizens fail to show up to their medical appointments that may not have been factored in to this research and may affect the results of the study.

_Additional research_

Additional research needs to be done on the Scholarship program to find out why the program intention was not met and why citizens on the Scholarship program are not responding to medical attention in terms of attending their scheduled appointments.

REFERENCES

Pereira, A. W. (2015). Bolsa Família and democracy in Brazil. Third World Quarterly, 36(9), 1682-1699.

Here is the [repo](https://github.com/andisiambuku/Appointment-Attendance) with the notebook. Feel free to leave a comment and critique or share more insights we could deduce.  

Until next time, may the code be with you.