In [42]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
import re
import geopandas
import folium

%matplotlib inline
In [43]:
df = pd.read_csv('./hospital_data.csv')
In [44]:
df.head()
Out[44]:
Region District FacilityName Type Town Ownership Latitude Longitude
0 Ashanti Offinso North A.M.E Zion Clinic Clinic Afrancho CHAG 7.40801 -1.96317
1 Ashanti Bekwai Municipal Abenkyiman Clinic Clinic Anwiankwanta Private 6.46312 -1.58592
2 Ashanti Adansi North Aboabo Health Centre Health Centre Aboabo No 2 Government 6.22393 -1.34982
3 Ashanti Afigya-Kwabre Aboabogya Health Centre Health Centre Aboabogya Government 6.84177 -1.61098
4 Ashanti Kwabre Aboaso Health Centre Health Centre Aboaso Government 6.84177 -1.61098
In [45]:
df.shape
Out[45]:
(3756, 8)
In [46]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3756 entries, 0 to 3755
Data columns (total 8 columns):
 #   Column        Non-Null Count  Dtype  
---  ------        --------------  -----  
 0   Region        3756 non-null   object 
 1   District      3756 non-null   object 
 2   FacilityName  3756 non-null   object 
 3   Type          3756 non-null   object 
 4   Town          3603 non-null   object 
 5   Ownership     3756 non-null   object 
 6   Latitude      3732 non-null   float64
 7   Longitude     3732 non-null   float64
dtypes: float64(2), object(6)
memory usage: 234.9+ KB
In [47]:
df.describe()
Out[47]:
Latitude Longitude
count 3732.000000 3732.000000
mean 6.955678 -1.074580
std 1.679332 1.021352
min 4.796180 -3.235880
25% 5.687642 -1.809792
50% 6.468705 -1.058117
75% 7.430555 -0.215870
max 11.146670 1.191440
In [48]:
df.Type.unique()
Out[48]:
array(['Clinic', 'Health Centre', 'Maternity Home', 'CHPS', 'Hospital',
       'District Hospital', 'Centre', 'RCH', 'Training Institution',
       'Municipal Health Directorate', 'Teaching Hospital',
       'Regional Hospital', 'CPHS', 'District Health Directorate',
       'Regional Health Directorate', 'Polyclinic', 'Municipal Hospital',
       'Municipal  Health Directorate', 'Metropolitan Hospital',
       'Metropolitan Health Directorate', 'DHD', 'Psychiatric Hospital',
       'Research Institution', 'Others', 'clinic'], dtype=object)
In [49]:
df.Type.value_counts()
Out[49]:
Clinic                             1171
Health Centre                       786
CHPS                                652
Maternity Home                      369
Hospital                            277
RCH                                 152
District Health Directorate          99
District Hospital                    82
Training Institution                 74
Others                               31
Polyclinic                           16
Regional Health Directorate           9
Regional Hospital                     9
Municipal Health Directorate          7
Municipal Hospital                    4
Teaching Hospital                     3
Psychiatric Hospital                  3
Centre                                2
Research Institution                  2
clinic                                2
Metropolitan Health Directorate       2
Metropolitan Hospital                 1
CPHS                                  1
Municipal  Health Directorate         1
DHD                                   1
Name: Type, dtype: int64
In [50]:
df.Ownership.value_counts()
Out[50]:
Government          2210
Private             1179
CHAG                 257
Quasi-Government      91
government             6
Islamic                4
NGO                    2
Maternity Home         2
private                2
Mission                1
Clinic                 1
Muslim                 1
Name: Ownership, dtype: int64
In [51]:
df.Ownership.unique()
Out[51]:
array(['CHAG', 'Private', 'Government', 'Quasi-Government', 'Islamic',
       'Muslim', 'Maternity Home', 'Clinic', 'private', 'NGO',
       'government', 'Mission'], dtype=object)
In [52]:
df.Region.unique()
Out[52]:
array(['Ashanti', 'Brong Ahafo', 'Central', 'Eastern', 'Greater Accra',
       'Northern', 'Upper East', 'Upper West', 'Volta', 'Western'],
      dtype=object)
In [53]:
region_district_df = df.groupby(['Region','District']).size().reset_index(name='Count')
In [54]:
# List all districts per region to find same district having different names
for val in list(region_district_df['Region'].unique()):
    districts = region_district_df.query('Region == @val')['District'].unique()
    print(" Region: {}, Number of Districts: {}\n{}\n".format(val, len(districts),districts))
 Region: Ashanti, Number of Districts: 27
['Adansi North' 'Adansi South' 'Afigya-Kwabre' 'Ahafo-Ano North'
 'Ahafo-Ano South' 'Amansie Central' 'Amansie West'
 'Asante-Akim North Municipal' 'Asante-Akim South' 'Atwima-Kwanwoma'
 'Atwima-Mponua' 'Atwima-Nwabiagya' 'Bekwai Municipal' 'Bosome Freho'
 'Bosomtwe' 'Ejisu-Juaben Municipal' 'Ejura Sekyeredumasi'
 'Kumasi Metropolitan' 'Kwabre' 'Mampong Municipal' 'Obuasi Municipal'
 'Offinso Municipal' 'Offinso North' 'Sekyere Afram Plains'
 'Sekyere Central' 'Sekyere East' 'Sekyere South']

 Region: Brong Ahafo, Number of Districts: 25
['Asunafo North Municipal' 'Asunafo South' 'Asutifi' 'Atebubu-Amanten'
 'Berekum Municipal' 'Dormaa East' 'Dormaa Municipal' 'Jaman North'
 'Jaman South' 'Kintampo North Municipal' 'Kintampo South' 'Nkoranza'
 'Nkoranza North' 'Pru' 'Sene' 'Sunyani' 'Sunyani Municipal'
 'Sunyani West' 'Tain' 'Tano North' 'Tano South' 'Techiman'
 'Techiman Municipal' 'Wenchi' 'Wenchi Municipal']

 Region: Central, Number of Districts: 17
['Abura-Asebu-Kwamankese' 'Agona East' 'Agona West Municipal'
 'Ajumako-Enyan-Essiam' 'Asikuma-Odoben-Brakwa' 'Assin North Municipal'
 'Assin South' 'Awutu Senya' 'Cape Coast Metropolitan' 'Efutu Municipal'
 'Gomoa East' 'Gomoa West' 'Komenda-Edina-Eguafo-Abirem Municipal'
 'Mfantseman' 'Twifu-Hemang-Lower Denkyira' 'Upper Denkyira East'
 'Upper Denkyira West']

 Region: Eastern, Number of Districts: 22
['Akwapim North' 'Akwapim South' 'Akyemansa' 'Asuogyamang' 'Atiwa'
 'Birim North' 'Birim South' 'Birim south' 'East Akim' 'Fanteakwa'
 'Kwaebibirem' 'Kwahu North' 'Kwahu South' 'Kwahu West' 'Kweabibirem'
 'Manya Krobo' 'New Juaben' 'New Juaben Municipal' 'Suhum Kraboa Coaltar'
 'Upper Manya' 'West Akim' 'Yilo Krobo']

 Region: Greater Accra, Number of Districts: 7
['Accra Metropolitan' 'Dangme East' 'Dangme West' 'Dangme west' 'Ga East'
 'Ga West' 'Tema Metropolitan']

 Region: Northern, Number of Districts: 18
['Bole' 'Bunkpurugu-Yunyuo' 'Central Gonja' 'East Gonja' 'East Mamprusi'
 'Gushegu' 'Karaga' 'Nanumba North' 'Nanumba South' 'Saboba-Chereponi'
 'Savelugu-Nanton' 'Sawla-Tuna-Kalba' 'Tamale Metropolitan'
 'Tolon-Kumbungu' 'West Gonja' 'West Mamprusi' 'Yendi' 'Zabzugu-Tatale']

 Region: Upper East, Number of Districts: 10
['Bawku Municipal' 'Bawku West' 'Bolgatanga Municipal' 'Bongo' 'Builsa'
 'Garu-Tempane' 'Kassena-Nankana' 'Kassena-Nankana West' 'Navrongo'
 'Talensi-Nabdam']

 Region: Upper West, Number of Districts: 10
['Jirapa' 'Lambussie' 'Lawra' 'Nadowli' 'Sissala East' 'Sissala West' 'Wa'
 'Wa East' 'Wa Municipal' 'Wa West']

 Region: Volta, Number of Districts: 15
['Adaklu-Anyigbe' 'Akatsi' 'Ho Municipal' 'Hohoe' 'Jasikan' 'Kadjebi'
 'Keta' 'Ketu' 'Kpando' 'Krachi East' 'Krachi West' 'Nkwanta'
 'North Tongu' 'South Dayi' 'South Tongu']

 Region: Western, Number of Districts: 20
['Ahanta West' 'Aowin Suaman' 'Bia' 'Bibiani-Anhwiaso-Bekwai' 'Ellembele'
 'Jomoro' 'Juabeso' 'Mpohor-Wassa East' 'Nzema East'
 'Nzema East Municipal' 'Prestea-Huni Valley' 'Pretea-Huni Valley'
 'Sefwi Wiawso' 'Sefwi-Akontombra' 'Shama' 'Shama Ahanta East'
 'Tarkwa Nsuaem Municipal' 'Wassa West' 'Wassa-Amenfi East'
 'Wassa-Amenfi West']

In [55]:
# Missing towns
missing_towns = df[df.Town.isnull()]
missing_towns
Out[55]:
Region District FacilityName Type Town Ownership Latitude Longitude
596 Ashanti Kumasi Metropolitan Amansie Enterprise Clinic Clinic NaN Private 6.415000 -1.375480
626 Ashanti Kumasi Metropolitan Restoration Clinic Clinic NaN Private 6.415000 -1.375480
645 Ashanti Mampong Municipal Calvary Health Service Clinic NaN Private 7.033970 -1.242940
653 Ashanti Offinso Municipal Offinso District Health Directorate District Health Directorate NaN Government 6.563090 -1.402680
969 Brong Ahafo Dormaa Municipal Florence Maternity Home Maternity Home NaN Maternity Home 7.277284 -2.876257
... ... ... ... ... ... ... ... ...
3726 Western Tarkwa Nsuaem Municipal Church of Pentecost Clinic Clinic NaN CHAG 5.299986 -1.992202
3727 Western Tarkwa Nsuaem Municipal Sam Jonna Clinic Clinic NaN Private 5.299986 -1.992202
3728 Western Tarkwa Nsuaem Municipal Divine Clinic Clinic NaN Private 5.299986 -1.992202
3730 Western Wassa-Amenfi West Kwabeng Clinic Clinic NaN Private 5.653611 -2.165901
3735 Western Wassa-Amenfi West Asanco SHS Sickbay Clinic NaN Private 5.653611 -2.165901

153 rows × 8 columns

In [56]:
missing_towns.shape
Out[56]:
(153, 8)
In [57]:
# missing coordinates
missing_coordinates = df[df.Latitude.isnull()|df.Longitude.isnull()]
missing_coordinates
Out[57]:
Region District FacilityName Type Town Ownership Latitude Longitude
357 Ashanti Bosome Freho Dunkura Health Centre Health Centre Dunkura Government NaN NaN
358 Ashanti Bosome Freho Yapesa St.Mary Clinic Clinic Yapesa CHAG NaN NaN
1651 Eastern Akyemansa St Johns Clinic Clinic Ofoase CHAG NaN NaN
2437 Northern Gushegu Nabuli Health Centre Health Centre Nabuli Government NaN NaN
2438 Northern Gushegu Damakung Clinic Clinic Damankung Government NaN NaN
2439 Northern Gushegu Gushegu Hospital Hospital Gushiegu Government NaN NaN
3416 Western Nzema East Municipal Ewuku CHPS CHPS Ewuku Government NaN NaN
3417 Western Nzema East Municipal Kutukrom Health Centre Health Centre Kutukrom Government NaN NaN
3663 Western Ellembele Aiyinase Health Centre Health Centre Aiyinase Government NaN NaN
3664 Western Ellembele Nana Benie M. Clinic Clinic NaN Private NaN NaN
3665 Western Ellembele A. B. Bokazo Clinic Clinic NaN Private NaN NaN
3666 Western Ellembele St. Martin de Porres Hospitakl Hospital NaN CHAG NaN NaN
3667 Western Ellembele Krisan Camp Clinic Clinic NaN CHAG NaN NaN
3668 Western Ellembele Esiama Health Centre Health Centre Esiama Government NaN NaN
3669 Western Ellembele Kamgbunli CHPS CHPS Kamgbunli Government NaN NaN
3670 Western Ellembele Mobile Clinic Clinic NaN Government NaN NaN
3671 Western Ellembele Ampain Refugee Camp Clinic Ampain Government NaN NaN
3672 Western Ellembele Aidoosuazo CHPS CHPS Aidoosuazo Government NaN NaN
3673 Western Ellembele Kwasikrom CHPS CHPS Kwasikrom Government NaN NaN
3674 Western Ellembele Asomase CHPS CHPS Asomase Government NaN NaN
3675 Western Ellembele Asasetre Health Centre Health Centre Asasetre Government NaN NaN
3676 Western Ellembele NASS SCH Clinic Clinic NaN Government NaN NaN
3677 Western Ellembele West African Rescue Association Clinic Clinic NaN Government NaN NaN
3678 Western Ellembele Ellembele District Health Directorate District Health Directorate NaN Government NaN NaN
In [58]:
missing_coordinates.shape
Out[58]:
(24, 8)
In [59]:
# save data with missing data into a dataframe so that client can help retrieve them.
missing_coordinates.to_csv('missing_coordinates.csv', index=False)
missing_towns.to_csv('missing_towns.csv', index=False)
In [60]:
df[df.District == 'Bosome Freho']
Out[60]:
Region District FacilityName Type Town Ownership Latitude Longitude
79 Ashanti Bosome Freho Asiwa Health Centre Health Centre Asiwa Government 6.42344 -1.33434
125 Ashanti Bosome Freho Detieso Community Clinic Clinic Detieso Government 6.47674 -1.44168
130 Ashanti Bosome Freho Duasi Community Clinic Clinic Duasi Government 6.46863 -1.39522
156 Ashanti Bosome Freho Gyasikrom Health Centre Clinic Gyasikrom Government 6.40145 -1.47313
357 Ashanti Bosome Freho Dunkura Health Centre Health Centre Dunkura Government NaN NaN
358 Ashanti Bosome Freho Yapesa St.Mary Clinic Clinic Yapesa CHAG NaN NaN

Assessment

Quality Issues

  • Erroneous Data types: Region, District, Type, Ownership
  • Missing Data: Latitude, Longitude
  • Different names for the same value under a column

Type:

* District Health Directorate,DHD
* Clinic, clinic
* Health Centre, Centre
* CHPS, CPHS
* Municipal  Health Directorate, Municipal Health Directorate

Ownership:

* Government, government
* Private, private
* Islamic, Muslim

Region: Western:

    * 'Prestea-Huni Valley','Pretea-Huni Valley'
    * 'Nzema East','Nzema East Municipal'
Eastern:
    * 'Birim South','Birim south'
    * 'Kwaebibirem','Kweabibirem'
    * 'New Juaben','New Juaben Municipal'
Brong Ahafo:
    * 'Sunyani' 'Sunyani Municipal'
    * 'Techiman','Techiman Municipal'
    * 'Wenchi','Wenchi Municipal'



  • Typographical Errors St. Martin de Porres Hospitakl

Missing Coordinates Comments

Cleaning

In [61]:
# Create copy of the original dataframe
clean_df = df.copy()
In [62]:
missing_coordinates
Out[62]:
Region District FacilityName Type Town Ownership Latitude Longitude
357 Ashanti Bosome Freho Dunkura Health Centre Health Centre Dunkura Government NaN NaN
358 Ashanti Bosome Freho Yapesa St.Mary Clinic Clinic Yapesa CHAG NaN NaN
1651 Eastern Akyemansa St Johns Clinic Clinic Ofoase CHAG NaN NaN
2437 Northern Gushegu Nabuli Health Centre Health Centre Nabuli Government NaN NaN
2438 Northern Gushegu Damakung Clinic Clinic Damankung Government NaN NaN
2439 Northern Gushegu Gushegu Hospital Hospital Gushiegu Government NaN NaN
3416 Western Nzema East Municipal Ewuku CHPS CHPS Ewuku Government NaN NaN
3417 Western Nzema East Municipal Kutukrom Health Centre Health Centre Kutukrom Government NaN NaN
3663 Western Ellembele Aiyinase Health Centre Health Centre Aiyinase Government NaN NaN
3664 Western Ellembele Nana Benie M. Clinic Clinic NaN Private NaN NaN
3665 Western Ellembele A. B. Bokazo Clinic Clinic NaN Private NaN NaN
3666 Western Ellembele St. Martin de Porres Hospitakl Hospital NaN CHAG NaN NaN
3667 Western Ellembele Krisan Camp Clinic Clinic NaN CHAG NaN NaN
3668 Western Ellembele Esiama Health Centre Health Centre Esiama Government NaN NaN
3669 Western Ellembele Kamgbunli CHPS CHPS Kamgbunli Government NaN NaN
3670 Western Ellembele Mobile Clinic Clinic NaN Government NaN NaN
3671 Western Ellembele Ampain Refugee Camp Clinic Ampain Government NaN NaN
3672 Western Ellembele Aidoosuazo CHPS CHPS Aidoosuazo Government NaN NaN
3673 Western Ellembele Kwasikrom CHPS CHPS Kwasikrom Government NaN NaN
3674 Western Ellembele Asomase CHPS CHPS Asomase Government NaN NaN
3675 Western Ellembele Asasetre Health Centre Health Centre Asasetre Government NaN NaN
3676 Western Ellembele NASS SCH Clinic Clinic NaN Government NaN NaN
3677 Western Ellembele West African Rescue Association Clinic Clinic NaN Government NaN NaN
3678 Western Ellembele Ellembele District Health Directorate District Health Directorate NaN Government NaN NaN
In [63]:
# Function to Convert Pascal Case Names to SnakeCase
def pascal_to_snake_case(name):
    return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
In [64]:
# make column names snake_case
clean_df.rename(columns=lambda x: pascal_to_snake_case(x), inplace=True, errors="raise")
In [65]:
# Verify
list(clean_df.columns)
Out[65]:
['region',
 'district',
 'facility_name',
 'type',
 'town',
 'ownership',
 'latitude',
 'longitude']

Missing Data

In [66]:
# Code
# Replace missing coordinates with available data
data_to_replace = {
    357: [6.466667,-1.433333],
    358: [6.4279761,-1.3352532],
    1651:[6.1695534,-1.1417168],
    2439:[9.9291129,-0.2140466],
    3416: [4.861389 ,-2.195556],
    3417: [5.033333, -2.266667],
    3663: [5.04348,-2.46458],
    3664: [5.0494868, -2.4820236],
    3669: [4.9743222, -2.4239446],
    3672: [5.1439822, -2.3725535],
    3678: [5.5485504, -0.1992678]
}

for index  in data_to_replace:
    clean_df.loc[index, 'latitude'] = data_to_replace[index][0]
    clean_df.loc[index, 'longitude'] = data_to_replace[index][1]
    
In [67]:
# Test
clean_df[clean_df.latitude.isnull()|clean_df.longitude.isnull()].shape
Out[67]:
(13, 8)

Different names for the same value under a column

In [68]:
# TYPE

# Code
clean_df.type.replace(['DHD','clinic','Centre','CPHS', 'Municipal  Health Directorate'],
                      ['District Health Directorate','Clinic','Health Centre','CHPS','Municipal Health Directorate'],
                      inplace=True)
In [69]:
# Test
clean_df.type.value_counts()
Out[69]:
Clinic                             1173
Health Centre                       788
CHPS                                653
Maternity Home                      369
Hospital                            277
RCH                                 152
District Health Directorate         100
District Hospital                    82
Training Institution                 74
Others                               31
Polyclinic                           16
Regional Hospital                     9
Regional Health Directorate           9
Municipal Health Directorate          8
Municipal Hospital                    4
Psychiatric Hospital                  3
Teaching Hospital                     3
Metropolitan Health Directorate       2
Research Institution                  2
Metropolitan Hospital                 1
Name: type, dtype: int64
In [70]:
# OWNERSHIP

## Code
clean_df.ownership.replace(['government','private','Muslim'],['Government','Private','Islamic'], inplace=True)
In [71]:
# Test
clean_df.ownership.value_counts()
Out[71]:
Government          2216
Private             1181
CHAG                 257
Quasi-Government      91
Islamic                5
NGO                    2
Maternity Home         2
Mission                1
Clinic                 1
Name: ownership, dtype: int64
In [72]:
# DISTRICT

# Code
clean_df.district.replace(['Pretea-Huni Valley','Nzema East','Birim south','Kweabibirem','New Juaben',
                              'Sunyani','Techiman','Wenchi'],
                          ['Prestea-Huni Valley','Nzema East Municipal','Birim South','Kwaebibirem',
                           'New Juaben Municipal','Sunyani Municipal','Techiman Municipal','Wenchi Municipal'],
                          inplace=True)
In [73]:
#Test
error_region_district_df = clean_df.groupby(['region','district']).size().reset_index(name='Count')
error_regions = ['Eastern','Western','Brong Ahafo']

for val in list(error_regions):
    districts = error_region_district_df.query('region == @val')['district'].unique()
    print(" Region: {}, Number of Districts: {}\n{}\n".format(val, len(districts),districts))
 Region: Eastern, Number of Districts: 19
['Akwapim North' 'Akwapim South' 'Akyemansa' 'Asuogyamang' 'Atiwa'
 'Birim North' 'Birim South' 'East Akim' 'Fanteakwa' 'Kwaebibirem'
 'Kwahu North' 'Kwahu South' 'Kwahu West' 'Manya Krobo'
 'New Juaben Municipal' 'Suhum Kraboa Coaltar' 'Upper Manya' 'West Akim'
 'Yilo Krobo']

 Region: Western, Number of Districts: 18
['Ahanta West' 'Aowin Suaman' 'Bia' 'Bibiani-Anhwiaso-Bekwai' 'Ellembele'
 'Jomoro' 'Juabeso' 'Mpohor-Wassa East' 'Nzema East Municipal'
 'Prestea-Huni Valley' 'Sefwi Wiawso' 'Sefwi-Akontombra' 'Shama'
 'Shama Ahanta East' 'Tarkwa Nsuaem Municipal' 'Wassa West'
 'Wassa-Amenfi East' 'Wassa-Amenfi West']

 Region: Brong Ahafo, Number of Districts: 22
['Asunafo North Municipal' 'Asunafo South' 'Asutifi' 'Atebubu-Amanten'
 'Berekum Municipal' 'Dormaa East' 'Dormaa Municipal' 'Jaman North'
 'Jaman South' 'Kintampo North Municipal' 'Kintampo South' 'Nkoranza'
 'Nkoranza North' 'Pru' 'Sene' 'Sunyani Municipal' 'Sunyani West' 'Tain'
 'Tano North' 'Tano South' 'Techiman Municipal' 'Wenchi Municipal']

Erroneous Datatypes

Convert Region, District, Type, Ownership to Category datatype

In [74]:
cols = ['region','district','type','ownership']
for col in cols:
    clean_df[col] = clean_df[col].astype('category')
In [75]:
clean_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3756 entries, 0 to 3755
Data columns (total 8 columns):
 #   Column         Non-Null Count  Dtype   
---  ------         --------------  -----   
 0   region         3756 non-null   category
 1   district       3756 non-null   category
 2   facility_name  3756 non-null   object  
 3   type           3756 non-null   category
 4   town           3603 non-null   object  
 5   ownership      3756 non-null   category
 6   latitude       3743 non-null   float64 
 7   longitude      3743 non-null   float64 
dtypes: category(4), float64(2), object(2)
memory usage: 143.7+ KB
In [76]:
## Save cleaned (partially) dataframe
clean_df.to_csv('cleaned_hospital_data.csv', index=False)

Visualization

In [77]:
# Distribution of Clinics Per Region
default_color = sb.color_palette()[0]
plt.figure(figsize=[18,10])
sb.countplot(data=clean_df, x='region', color=default_color)


# add annotations
n_points = clean_df.shape[0]
cat_counts = clean_df.region.value_counts()
locs, labels = plt.xticks() # get the current tick locations and labels

# loop through each pair of locations and labels
for loc, label in zip(locs, labels):

    # get the text property for the label to get the correct count
    count = cat_counts[label.get_text()]
    pct_string = '{:0.2f}%'.format(100*count/n_points)

    # print the annotation just below the top of the bar
    plt.text(loc, count-30, pct_string, ha = 'center', color = 'w', fontsize=15)
    
    
# plt.ylabel('Number of Health Facilities', fontsize=20)
plt.ylabel('')
plt.xlabel('Regions', labelpad=10, fontsize=20)
plt.title('Distribution of Health Facilities Per Region', fontsize=20)
plt.yticks([])
plt.xticks(fontsize=15)
plt.box(on=None);
In [78]:
plt.figure(figsize=[20,10])
sb.countplot(data=clean_df, x='type', color=default_color);
plt.xticks(rotation=80, fontsize=15);
plt.xlabel('Type of Facility', labelpad=20, fontsize=20);
plt.ylabel('Number of Health Facilities', fontsize=20);
plt.title('Distribution of the Type of Health Facilities', fontsize=20);
In [79]:
plt.figure(figsize=[20,10])
sb.countplot(data=clean_df, x='ownership', color=default_color);
plt.xticks(rotation=80, fontsize=15);
plt.xlabel('Owner of Facility', labelpad=20, fontsize=20);
plt.ylabel('Number of Health Facilities', fontsize=20);
plt.title('Distribution of the Ownership of Health Facilities', fontsize=20);
In [80]:
plt.figure(figsize=[25,10])
ax = sb.countplot(data=clean_df, x='region', hue='ownership');


plt.xticks(rotation=80, fontsize=15);
plt.xlabel('Owner of Facility', labelpad=20, fontsize=20);
plt.ylabel('Number of Health Facilities', fontsize=20);
plt.title('Distribution of the Ownership of Health Facilities', fontsize=20);
ax.legend(title='Owners of Health Facilities',loc = 1, ncol = 2);
In [81]:
clean_df
Out[81]:
region district facility_name type town ownership latitude longitude
0 Ashanti Offinso North A.M.E Zion Clinic Clinic Afrancho CHAG 7.408010 -1.963170
1 Ashanti Bekwai Municipal Abenkyiman Clinic Clinic Anwiankwanta Private 6.463120 -1.585920
2 Ashanti Adansi North Aboabo Health Centre Health Centre Aboabo No 2 Government 6.223930 -1.349820
3 Ashanti Afigya-Kwabre Aboabogya Health Centre Health Centre Aboabogya Government 6.841770 -1.610980
4 Ashanti Kwabre Aboaso Health Centre Health Centre Aboaso Government 6.841770 -1.610980
... ... ... ... ... ... ... ... ...
3751 Western Sefwi-Akontombra Ackaakrom CHPS CHPS Ackaakrom Government 6.041831 -2.875169
3752 Western Sefwi-Akontombra Apprutu CHPS CHPS Apprutu Government 6.041831 -2.875169
3753 Western Sefwi-Akontombra Kojokrom CHPS CHPS Kojokrom Government 6.041831 -2.875169
3754 Western Sefwi-Akontombra Yawkrom CHPS CHPS Yawkrom Government 6.041831 -2.875169
3755 Western Sefwi-Akontombra Kofikrom CHPS CHPS Kofikrom Government 6.041831 -2.875169

3756 rows × 8 columns

In [82]:
gdf = geopandas.GeoDataFrame(
    clean_df, geometry=geopandas.points_from_xy(clean_df.longitude, clean_df.latitude))
In [84]:
gdf.crs = {'init': 'epsg:4326'}
In [85]:
regions = geopandas.read_file('./Map_of_Regions_in_Ghana.shx')
ax = regions.plot(figsize=(25,25), color='whitesmoke', linestyle=':', edgecolor='black')
gdf.to_crs(epsg=32630).plot(markersize=1, ax=ax, label='Distribution of Health Facilities Across Ghana');
In [ ]:
# gdf.crs = {'init': 'epsg:4326'}
In [86]:
# Use Facilities with coordinates
gdf = gdf[gdf.latitude.notnull()]
In [87]:
# # Create a map
# import folium
# f = folium.Figure(width=1200, height=1500)
# m = folium.Map(location=[7.9528, -1.0307], tiles='openstreetmap', zoom_start=9)

# # Add points to the map
# for idx, row in gdf.iterrows():
#    folium.Marker([row['latitude'], row['longitude']], popup=row['facility_name']).add_to(m)

# # Display the map
# f.add_child(m)
# f
In [88]:
def plot_regional_maps(gdf, coordinates, zoom, region_name):
    """
    gdf (Geopandas dataframe): This is a geopandas dataframe
    coordinates (list): List containining [Latitiude, Longitude]. Eg.[6.7373876, -1.8975697]
    zoom (int): The zoom level to start with. Eg. 2
    """
    m = folium.Map(location=coordinates, tiles='openstreetmap', zoom_start=zoom)
    for idx, row in gdf.iterrows():
        folium.Marker([row['latitude'], row['longitude']], popup=row['facility_name']).add_to(m)
    m.save("{}_map.html".format(region_name.replace(" ","_")))
In [89]:
regional_coordinates = {
    'Ashanti': [6.7373876, -1.8975697],
    'Brong Ahafo': [7.5810711, -2.5497912],
    'Central':[5.667745, -1.8332853],
    'Eastern': [6.4576381, -1.0233539],
    'Greater Accra': [5.7452223, -0.4538212],
    'Northern': [9.3328873, -2.2296366],
    'Upper East': [10.7213849, -1.3312247],
    'Upper West': [10.3357329, -2.7159009],
    'Volta': [7.2555048,-0.7223261],
    'Western': [5.8935708, -3.4580734 ]
}
In [90]:
for region_name in regional_coordinates:
    geo_df = gdf.query('region == @region_name')
    plot_regional_maps(gdf = geo_df, coordinates = regional_coordinates[region_name],
                       zoom = 9, region_name=region_name)

Regional Distribution of Health Facilities on a Map

In [91]:
from IPython.display import IFrame
In [92]:
IFrame(src='./Ashanti_map.html',width=800, height=700)
Out[92]:
In [93]:
IFrame(src='./Brong_Ahafo_map.html',width=800, height=700)
Out[93]:
In [94]:
IFrame(src='./Central_map.html',width=800, height=700)
Out[94]:
In [95]:
IFrame(src='./Eastern_map.html',width=800, height=700)
Out[95]:
In [96]:
IFrame(src='./Greater_Accra_map.html',width=800, height=700)
Out[96]:
In [97]:
IFrame(src='./Northern_map.html',width=800, height=700)
Out[97]:
In [98]:
IFrame(src='./Upper_East_map.html',width=800, height=700)
Out[98]:
In [99]:
IFrame(src='./Upper_West_map.html',width=800, height=700)
Out[99]:
In [100]:
IFrame(src='./Volta_map.html',width=800, height=700)
Out[100]:
In [101]:
IFrame(src='./Western_map.html',width=800, height=700)
Out[101]:
In [ ]: