We plot and analyze the life expectancy in Kenya by age, gender and counties. The data is from the 2019 Kenya Population and Housing Census. The data is available in the Kenya National Bureau of Statistics website 1. We will extract the data from Table 5.7, page 70 of the KPHC Census Analytical Report on Population Dynamics Volume VIII 2
The following is an image of the table we will be using:
Code
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from adjustText import adjust_text
from IPython.display import display, Markdown
Code
= {
data_dict '', 'COUNTY/RESIDENCE'): [
("Kenya",
"Rural",
"Urban",
"Mombasa",
"Kwale",
"Kilifi",
"Tana River",
"Lamu",
"Taita Taveta",
"Garissa",
"Wajir",
"Mandera",
"Marsabit",
"Isiolo",
"Meru",
"Tharaka-Nithi",
"Embu",
"Kitui",
"Machakos",
"Makueni",
"Nyandarua",
"Nyeri",
"Kirinyaga",
"Murang'a",
"Kiambu",
"Turkana",
"West Pokot",
"Samburu",
"Trans Nzoia",
"Uasin Gishu",
"Elgeyo Marakwet",
"Nandi",
"Baringo",
"Laikipia",
"Nakuru",
"Narok",
"Kajiado",
"Kericho",
"Bomet",
"Kakamega",
"Vihiga",
"Bungoma",
"Busia",
"Siaya",
"Kisumu",
"Homa Bay",
"Migori",
"Kisii",
"Nyamira",
"Nairobi"
],"MALE", "birth (age 0)"): [
(60.6,
60.3,
63.0,
65.7,
58.2,
57.8,
56.2,
64.1,
61.2,
57.4,
56.7,
57.3,
57.9,
60.1,
62.2,
63.8,
58.7,
55.7,
57.9,
58.1,
58.0,
66.4,
59.9,
58.1,
60.8,
55.9,
57.6,
58.5,
64.4,
63.6,
57.9,
60.0,
65.4,
59.2,
58.3,
57.8,
57.8,
58.1,
58.1,
63.4,
59.8,
65.5,
62.3,
53.4,
54.0,
50.5,
50.5,
56.1,
55.3,
62.6
],"MALE", "age 20"): [
(44.9,
44.6,
47.2,
51.0,
42.9,
43.0,
42.5,
50.9,
45.9,
43.1,
42.8,
43.0,
42.6,
45.9,
47.8,
47.3,
43.3,
40.3,
41.9,
42.2,
42.2,
49.9,
44.0,
42.6,
44.4,
42.1,
42.9,
42.6,
49.6,
48.0,
42.4,
44.6,
50.3,
42.6,
43.6,
43.0,
41.9,
42.4,
42.9,
49.5,
46.2,
50.6,
48.8,
39.9,
40.1,
38.7,
40.1,
40.7,
40.0,
48.4
],"MALE", "age 60"): [
(14.2,
14.5,
15.3,
17.7,
14.0,
14.1,
14.0,
17.7,
15.7,
14.1,
14.1,
14.1,
14.7,
15.7,
16.4,
16.2,
14.9,
14.0,
13.7,
13.8,
13.8,
16.3,
15.1,
13.9,
15.2,
14.5,
14.1,
14.6,
17.1,
16.5,
13.9,
15.3,
17.4,
14.7,
15.0,
14.1,
13.7,
13.9,
14.0,
17.1,
15.8,
17.6,
16.8,
13.9,
14.0,
13.7,
14.0,
14.2,
14.0,
16.6
],"MALE", "age 80"): [
(5.7,
5.4,
5.6,
5.9,
5.3,
5.3,
5.2,
5.9,
5.6,
5.2,
5.2,
5.2,
5.5,
5.6,
5.7,
5.7,
5.5,
5.4,
5.3,
5.3,
5.3,
6.0,
5.5,
5.3,
5.5,
5.4,
5.2,
5.5,
5.8,
5.7,
5.3,
5.5,
5.9,
5.5,
5.5,
5.3,
5.3,
5.3,
5.3,
5.8,
5.6,
5.9,
5.7,
5.4,
5.4,
5.3,
5.4,
5.4,
5.4,
5.7
],"FEMALE", "birth (age 0)"): [
(66.5,
66.2,
68.6,
71.1,
60.7,
59.2,
58.6,
68.9,
69.2,
60.5,
62.0,
60.5,
62.6,
59.6,
68.2,
70.3,
70.1,
68.8,
63.9,
62.4,
63.2,
75.8,
71.1,
64.7,
72.8,
60.0,
61.1,
67.4,
67.9,
71.7,
62.5,
70.4,
68.9,
71.9,
69.1,
61.9,
63.5,
62.9,
63.6,
66.1,
62.1,
68.2,
66.2,
61.6,
63.1,
60.2,
60.6,
66.9,
66.2,
65.2
],"FEMALE", "age 20"): [
(50.8,
50.9,
52.9,
55.3,
45.5,
44.6,
44.4,
53.3,
52.9,
45.6,
46.4,
45.5,
46.4,
44.4,
52.8,
53.1,
53.9,
52.3,
47.7,
46.6,
47.2,
59.6,
54.8,
48.3,
55.8,
45.6,
45.8,
51.3,
52.5,
55.2,
46.7,
54.3,
52.4,
54.5,
53.8,
46.3,
47.4,
47.0,
47.5,
51.3,
49.0,
52.6,
51.8,
47.2,
48.6,
47.6,
48.9,
50.6,
50.2,
50.2
],"FEMALE", "age 60"): [
(17.2,
17.7,
18.4,
20.0,
16.2,
15.9,
15.9,
18.9,
18.7,
16.2,
16.4,
16.2,
16.0,
15.4,
18.7,
18.8,
19.2,
18.4,
16.8,
16.5,
16.7,
22.2,
19.7,
17.0,
20.2,
15.7,
16.3,
18.0,
18.5,
19.9,
16.5,
19.4,
18.5,
19.5,
19.2,
16.4,
16.7,
16.6,
16.8,
18.0,
17.0,
18.6,
18.2,
16.3,
16.8,
16.5,
17.0,
17.7,
17.5,
17.5
],"FEMALE", "age 80"): [
(6.2,
6.3,
6.4,
6.5,
6.1,
6.0,
6.0,
6.3,
6.2,
6.1,
6.2,
6.1,
5.7,
5.7,
6.2,
6.3,
6.4,
6.2,
6.3,
6.2,
6.2,
7.4,
6.5,
6.3,
6.6,
5.7,
6.1,
6.1,
6.2,
6.5,
6.2,
6.4,
6.2,
6.4,
6.3,
6.2,
6.3,
6.2,
6.3,
6.1,
5.9,
6.2,
6.1,
5.8,
5.9,
5.8,
5.9,
6.0,
6.0,
6.0
]
}= pd.DataFrame(data_dict)
df 0], inplace=True)
df.set_index(df.columns[ df
MALE | FEMALE | |||||||
---|---|---|---|---|---|---|---|---|
birth (age 0) | age 20 | age 60 | age 80 | birth (age 0) | age 20 | age 60 | age 80 | |
(, COUNTY/RESIDENCE) | ||||||||
Kenya | 60.6 | 44.9 | 14.2 | 5.7 | 66.5 | 50.8 | 17.2 | 6.2 |
Rural | 60.3 | 44.6 | 14.5 | 5.4 | 66.2 | 50.9 | 17.7 | 6.3 |
Urban | 63.0 | 47.2 | 15.3 | 5.6 | 68.6 | 52.9 | 18.4 | 6.4 |
Mombasa | 65.7 | 51.0 | 17.7 | 5.9 | 71.1 | 55.3 | 20.0 | 6.5 |
Kwale | 58.2 | 42.9 | 14.0 | 5.3 | 60.7 | 45.5 | 16.2 | 6.1 |
Kilifi | 57.8 | 43.0 | 14.1 | 5.3 | 59.2 | 44.6 | 15.9 | 6.0 |
Tana River | 56.2 | 42.5 | 14.0 | 5.2 | 58.6 | 44.4 | 15.9 | 6.0 |
Lamu | 64.1 | 50.9 | 17.7 | 5.9 | 68.9 | 53.3 | 18.9 | 6.3 |
Taita Taveta | 61.2 | 45.9 | 15.7 | 5.6 | 69.2 | 52.9 | 18.7 | 6.2 |
Garissa | 57.4 | 43.1 | 14.1 | 5.2 | 60.5 | 45.6 | 16.2 | 6.1 |
Wajir | 56.7 | 42.8 | 14.1 | 5.2 | 62.0 | 46.4 | 16.4 | 6.2 |
Mandera | 57.3 | 43.0 | 14.1 | 5.2 | 60.5 | 45.5 | 16.2 | 6.1 |
Marsabit | 57.9 | 42.6 | 14.7 | 5.5 | 62.6 | 46.4 | 16.0 | 5.7 |
Isiolo | 60.1 | 45.9 | 15.7 | 5.6 | 59.6 | 44.4 | 15.4 | 5.7 |
Meru | 62.2 | 47.8 | 16.4 | 5.7 | 68.2 | 52.8 | 18.7 | 6.2 |
Tharaka-Nithi | 63.8 | 47.3 | 16.2 | 5.7 | 70.3 | 53.1 | 18.8 | 6.3 |
Embu | 58.7 | 43.3 | 14.9 | 5.5 | 70.1 | 53.9 | 19.2 | 6.4 |
Kitui | 55.7 | 40.3 | 14.0 | 5.4 | 68.8 | 52.3 | 18.4 | 6.2 |
Machakos | 57.9 | 41.9 | 13.7 | 5.3 | 63.9 | 47.7 | 16.8 | 6.3 |
Makueni | 58.1 | 42.2 | 13.8 | 5.3 | 62.4 | 46.6 | 16.5 | 6.2 |
Nyandarua | 58.0 | 42.2 | 13.8 | 5.3 | 63.2 | 47.2 | 16.7 | 6.2 |
Nyeri | 66.4 | 49.9 | 16.3 | 6.0 | 75.8 | 59.6 | 22.2 | 7.4 |
Kirinyaga | 59.9 | 44.0 | 15.1 | 5.5 | 71.1 | 54.8 | 19.7 | 6.5 |
Murang'a | 58.1 | 42.6 | 13.9 | 5.3 | 64.7 | 48.3 | 17.0 | 6.3 |
Kiambu | 60.8 | 44.4 | 15.2 | 5.5 | 72.8 | 55.8 | 20.2 | 6.6 |
Turkana | 55.9 | 42.1 | 14.5 | 5.4 | 60.0 | 45.6 | 15.7 | 5.7 |
West Pokot | 57.6 | 42.9 | 14.1 | 5.2 | 61.1 | 45.8 | 16.3 | 6.1 |
Samburu | 58.5 | 42.6 | 14.6 | 5.5 | 67.4 | 51.3 | 18.0 | 6.1 |
Trans Nzoia | 64.4 | 49.6 | 17.1 | 5.8 | 67.9 | 52.5 | 18.5 | 6.2 |
Uasin Gishu | 63.6 | 48.0 | 16.5 | 5.7 | 71.7 | 55.2 | 19.9 | 6.5 |
Elgeyo Marakwet | 57.9 | 42.4 | 13.9 | 5.3 | 62.5 | 46.7 | 16.5 | 6.2 |
Nandi | 60.0 | 44.6 | 15.3 | 5.5 | 70.4 | 54.3 | 19.4 | 6.4 |
Baringo | 65.4 | 50.3 | 17.4 | 5.9 | 68.9 | 52.4 | 18.5 | 6.2 |
Laikipia | 59.2 | 42.6 | 14.7 | 5.5 | 71.9 | 54.5 | 19.5 | 6.4 |
Nakuru | 58.3 | 43.6 | 15.0 | 5.5 | 69.1 | 53.8 | 19.2 | 6.3 |
Narok | 57.8 | 43.0 | 14.1 | 5.3 | 61.9 | 46.3 | 16.4 | 6.2 |
Kajiado | 57.8 | 41.9 | 13.7 | 5.3 | 63.5 | 47.4 | 16.7 | 6.3 |
Kericho | 58.1 | 42.4 | 13.9 | 5.3 | 62.9 | 47.0 | 16.6 | 6.2 |
Bomet | 58.1 | 42.9 | 14.0 | 5.3 | 63.6 | 47.5 | 16.8 | 6.3 |
Kakamega | 63.4 | 49.5 | 17.1 | 5.8 | 66.1 | 51.3 | 18.0 | 6.1 |
Vihiga | 59.8 | 46.2 | 15.8 | 5.6 | 62.1 | 49.0 | 17.0 | 5.9 |
Bungoma | 65.5 | 50.6 | 17.6 | 5.9 | 68.2 | 52.6 | 18.6 | 6.2 |
Busia | 62.3 | 48.8 | 16.8 | 5.7 | 66.2 | 51.8 | 18.2 | 6.1 |
Siaya | 53.4 | 39.9 | 13.9 | 5.4 | 61.6 | 47.2 | 16.3 | 5.8 |
Kisumu | 54.0 | 40.1 | 14.0 | 5.4 | 63.1 | 48.6 | 16.8 | 5.9 |
Homa Bay | 50.5 | 38.7 | 13.7 | 5.3 | 60.2 | 47.6 | 16.5 | 5.8 |
Migori | 50.5 | 40.1 | 14.0 | 5.4 | 60.6 | 48.9 | 17.0 | 5.9 |
Kisii | 56.1 | 40.7 | 14.2 | 5.4 | 66.9 | 50.6 | 17.7 | 6.0 |
Nyamira | 55.3 | 40.0 | 14.0 | 5.4 | 66.2 | 50.2 | 17.5 | 6.0 |
Nairobi | 62.6 | 48.4 | 16.6 | 5.7 | 65.2 | 50.2 | 17.5 | 6.0 |
Plots and Insights
Code
def life_expectancy_analysis(age_column: str, axis_margin: float = 1.2):
### Life Expectancy
display(Markdown("\n"
f"### Life Expectancy at {age_column}"
"\n"))
= df.loc["Kenya"]
kenya = df.loc["Rural"]
rural = df.loc["Urban"]
urban = [kenya.name, rural.name, urban.name]
drop_columns = df[('MALE', age_column)].drop(drop_columns).tolist()
males = df[('FEMALE', age_column)].drop(drop_columns).tolist()
females = df.index.drop(drop_columns).tolist()
counties #### Plotting
display(Markdown("\n"
f"#### Plot - {age_column}"
"\n"))
=(12, 10))
plt.figure(figsize# Plot the counties
sns.scatterplot(=males, y=females, s=60, alpha=0.9, label='Counties Life Expectancy')
x# Plot reference lines for Kenya, Rural, Urban
plt.axvline(=kenya[('MALE', age_column)], color='r', linestyle='dashdot', alpha=0.3)
x
plt.axhline(=kenya[('FEMALE', age_column)], color='r', linestyle='dashdot', alpha=0.3,
y='National Life Expectancy')
label
plt.axvline(=rural[('MALE', age_column)], color='g', linestyle='dashdot', alpha=0.3)
x
plt.axhline(=rural[('FEMALE', age_column)], color='g', linestyle='dashdot', alpha=0.3,
y='Rural Life Expectancy')
label
plt.axvline(=urban[('MALE', age_column)], color='b', linestyle='dashdot', alpha=0.3)
x
plt.axhline(=urban[('FEMALE', age_column)], color='b', linestyle='dashdot', alpha=0.3,
y='Urban Life Expectancy')
label# Add diagonal line representing equal life expectancy
= min(min(males), min(females))
min_val = max(max(males), max(females))
max_val
plt.plot(='gray', linestyle='solid',
[min_val, max_val], [min_val, max_val], color=0.3, label='Equal Life Expectancy')
alpha# Add labels for reference points
= [
texts =10)
plt.text(males[i], females[i], counties[i], fontsizefor i
in range(len(counties))]
=dict(arrowstyle='-', color='black', lw=0.5))
adjust_text(texts, arrowprops# Adjust limits based on scatter data
min(males) - axis_margin, max(males) + axis_margin)
plt.xlim(min(females) - axis_margin, max(females) + axis_margin)
plt.ylim(True, alpha=0.2)
plt.grid(
plt.title(f'Life Expectancy at {age_column} by County in Kenya: Male vs Female',
=16)
fontsize'Male Life Expectancy (years)', fontsize=14)
plt.xlabel('Female Life Expectancy (years)', fontsize=14)
plt.ylabel(='upper left')
plt.legend(loc
plt.tight_layout()
plt.show()#### Analysis of Life Expectancy
display(Markdown("\n"
f"#### Analysis of Life Expectancy at {age_column}"
"\n"))
= kenya[('MALE', age_column)]
kenya_males = kenya[('FEMALE', age_column)]
kenya_females = rural[('MALE', age_column)]
rural_males = rural[('FEMALE', age_column)]
rural_females = urban[('MALE', age_column)]
urban_males = urban[('FEMALE', age_column)]
urban_females = pd.DataFrame({
county_analysis_df 'COUNTY': counties,
'MALE': males,
'FEMALE': females
})##### Top 5 counties greatest and least life expectancy
display(Markdown("\n"
f"##### Top 5 counties with greatest and least life expectancy - {age_column}"
"\n"))
= county_analysis_df\
men_by_county_asc "MALE", ascending=True)\
.sort_values(5)\
.head(apply(lambda x: f'{x["COUNTY"] } - {x["MALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
men_by_county_desc "MALE", ascending=False)\
.sort_values(5)\
.head(apply(lambda x: f'{x["COUNTY"] } - {x["MALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
women_by_county_asc "FEMALE", ascending=True)\
.sort_values(5)\
.head(apply(lambda x: f'{x["COUNTY"] } - {x["FEMALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
women_by_county_desc "FEMALE", ascending=False)\
.sort_values(5)\
.head(apply(lambda x: f'{x["COUNTY"] } - {x["FEMALE"]}', axis=1)\
.
.tolist()
display(pd.DataFrame({ '[men] by_county_desc': men_by_county_desc,
'[men] by_county_asc': men_by_county_asc,
'[women] by_county_desc': women_by_county_desc,
'[women] by_county_asc': women_by_county_asc,
=range(1, 6)))
}, index# Analysis
def above_or_below(reference: str, males: float, females: float):
= county_analysis_df\
men_by_county_below "MALE"] <= males]\
[county_analysis_df["MALE", ascending=True)\
.sort_values(apply(lambda x: f'{x["COUNTY"] } - {x["MALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
men_by_county_above "MALE"] > males]\
[county_analysis_df["MALE", ascending=False)\
.sort_values(apply(lambda x: f'{x["COUNTY"] } - {x["MALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
women_by_county_below "FEMALE"] <= females]\
[county_analysis_df["FEMALE", ascending=True)\
.sort_values(apply(lambda x: f'{x["COUNTY"] } - {x["FEMALE"]}', axis=1)\
.
.tolist()= county_analysis_df\
women_by_county_above "FEMALE"] > females]\
[county_analysis_df["FEMALE", ascending=False)\
.sort_values(apply(lambda x: f'{x["COUNTY"] } - {x["FEMALE"]}', axis=1)\
.
.tolist()return pd.DataFrame.from_dict({
f'({len(men_by_county_above)}) [men] above {reference}': men_by_county_above[:6],
f'({len(men_by_county_below)}) [men] below {reference}': men_by_county_below[:6],
f'({len(women_by_county_above)}) [women] above {reference}': women_by_county_above[:6],
f'({len(women_by_county_below)}) [women] below {reference}': women_by_county_below[:6],
='index').T.reindex(index=range(1, 6))
}, orient##### Top 5 counties above and below national life expectancy"
display(Markdown("\n"
f"##### Top 5 counties above and below National life expectancy - {age_column}"
"\n"))
'national', kenya_males, kenya_females))
display(above_or_below(##### Top 5 counties above and below urban life expectancy
display(Markdown("\n"
f"##### Top 5 counties above and below Rural life expectancy - {age_column}"
"\n"))
'rural', rural_males, rural_females))
display(above_or_below(##### Top 5 counties above and below urban life expectancy
display(Markdown("\n"
f"##### Top 5 counties above and below Urban life expectancy - {age_column}"
"\n"))
'urban', urban_males, urban_females))
display(above_or_below(##### Top 5 counties where men have higher life expectancy than women
= county_analysis_df\
men_greater_than_women "FEMALE"] < county_analysis_df["MALE"]]
[county_analysis_df[if men_greater_than_women is not None and not men_greater_than_women.empty:
display(Markdown("\n"
f"##### Top 5 counties where men have higher life expectancy than women - {age_column}"
"\n"))
"FEMALE", ascending=True))
display(men_greater_than_women.sort_values(
display(Markdown("\n"
f"##### Other Statistics - {age_column}"
"\n"))
display(county_analysis_df.describe())
Code
'birth (age 0)') life_expectancy_analysis(
Life Expectancy at birth (age 0)
Plot - birth (age 0)
Analysis of Life Expectancy at birth (age 0)
Top 5 counties with greatest and least life expectancy - birth (age 0)
[men] by_county_desc | [men] by_county_asc | [women] by_county_desc | [women] by_county_asc | |
---|---|---|---|---|
1 | Nyeri - 66.4 | Homa Bay - 50.5 | Nyeri - 75.8 | Tana River - 58.6 |
2 | Mombasa - 65.7 | Migori - 50.5 | Kiambu - 72.8 | Kilifi - 59.2 |
3 | Bungoma - 65.5 | Siaya - 53.4 | Laikipia - 71.9 | Isiolo - 59.6 |
4 | Baringo - 65.4 | Kisumu - 54.0 | Uasin Gishu - 71.7 | Turkana - 60.0 |
5 | Trans Nzoia - 64.4 | Nyamira - 55.3 | Kirinyaga - 71.1 | Homa Bay - 60.2 |
Top 5 counties above and below National life expectancy - birth (age 0)
(14) [men] above national | (33) [men] below national | (19) [women] above national | (28) [women] below national | |
---|---|---|---|---|
1 | Mombasa - 65.7 | Homa Bay - 50.5 | Kiambu - 72.8 | Kilifi - 59.2 |
2 | Bungoma - 65.5 | Siaya - 53.4 | Laikipia - 71.9 | Isiolo - 59.6 |
3 | Baringo - 65.4 | Kisumu - 54.0 | Uasin Gishu - 71.7 | Turkana - 60.0 |
4 | Trans Nzoia - 64.4 | Nyamira - 55.3 | Kirinyaga - 71.1 | Homa Bay - 60.2 |
5 | Lamu - 64.1 | Kitui - 55.7 | Mombasa - 71.1 | Garissa - 60.5 |
Top 5 counties above and below Rural life expectancy - birth (age 0)
(14) [men] above rural | (33) [men] below rural | (19) [women] above rural | (28) [women] below rural | |
---|---|---|---|---|
1 | Mombasa - 65.7 | Homa Bay - 50.5 | Kiambu - 72.8 | Kilifi - 59.2 |
2 | Bungoma - 65.5 | Siaya - 53.4 | Laikipia - 71.9 | Isiolo - 59.6 |
3 | Baringo - 65.4 | Kisumu - 54.0 | Uasin Gishu - 71.7 | Turkana - 60.0 |
4 | Trans Nzoia - 64.4 | Nyamira - 55.3 | Kirinyaga - 71.1 | Homa Bay - 60.2 |
5 | Lamu - 64.1 | Kitui - 55.7 | Mombasa - 71.1 | Garissa - 60.5 |
Top 5 counties above and below Urban life expectancy - birth (age 0)
(9) [men] above urban | (38) [men] below urban | (14) [women] above urban | (33) [women] below urban | |
---|---|---|---|---|
1 | Mombasa - 65.7 | Migori - 50.5 | Kiambu - 72.8 | Kilifi - 59.2 |
2 | Bungoma - 65.5 | Siaya - 53.4 | Laikipia - 71.9 | Isiolo - 59.6 |
3 | Baringo - 65.4 | Kisumu - 54.0 | Uasin Gishu - 71.7 | Turkana - 60.0 |
4 | Trans Nzoia - 64.4 | Nyamira - 55.3 | Mombasa - 71.1 | Homa Bay - 60.2 |
5 | Lamu - 64.1 | Kitui - 55.7 | Kirinyaga - 71.1 | Garissa - 60.5 |
Top 5 counties where men have higher life expectancy than women - birth (age 0)
COUNTY | MALE | FEMALE | |
---|---|---|---|
10 | Isiolo | 60.1 | 59.6 |
Other Statistics - birth (age 0)
MALE | FEMALE | |
---|---|---|
count | 47.000000 | 47.000000 |
mean | 59.110638 | 65.391489 |
std | 3.684706 | 4.327959 |
min | 50.500000 | 58.600000 |
25% | 57.500000 | 61.950000 |
50% | 58.100000 | 64.700000 |
75% | 61.700000 | 68.900000 |
max | 66.400000 | 75.800000 |
Code
'age 20') life_expectancy_analysis(
Life Expectancy at age 20
Plot - age 20
Analysis of Life Expectancy at age 20
Top 5 counties with greatest and least life expectancy - age 20
[men] by_county_desc | [men] by_county_asc | [women] by_county_desc | [women] by_county_asc | |
---|---|---|---|---|
1 | Mombasa - 51.0 | Homa Bay - 38.7 | Nyeri - 59.6 | Tana River - 44.4 |
2 | Lamu - 50.9 | Siaya - 39.9 | Kiambu - 55.8 | Isiolo - 44.4 |
3 | Bungoma - 50.6 | Nyamira - 40.0 | Mombasa - 55.3 | Kilifi - 44.6 |
4 | Baringo - 50.3 | Migori - 40.1 | Uasin Gishu - 55.2 | Kwale - 45.5 |
5 | Nyeri - 49.9 | Kisumu - 40.1 | Kirinyaga - 54.8 | Mandera - 45.5 |
Top 5 counties above and below National life expectancy - age 20
(15) [men] above national | (32) [men] below national | (20) [women] above national | (27) [women] below national | |
---|---|---|---|---|
1 | Lamu - 50.9 | Siaya - 39.9 | Kiambu - 55.8 | Isiolo - 44.4 |
2 | Bungoma - 50.6 | Nyamira - 40.0 | Mombasa - 55.3 | Kilifi - 44.6 |
3 | Baringo - 50.3 | Migori - 40.1 | Uasin Gishu - 55.2 | Kwale - 45.5 |
4 | Nyeri - 49.9 | Kisumu - 40.1 | Kirinyaga - 54.8 | Mandera - 45.5 |
5 | Trans Nzoia - 49.6 | Kitui - 40.3 | Laikipia - 54.5 | Garissa - 45.6 |
Top 5 counties above and below Rural life expectancy - age 20
(15) [men] above rural | (32) [men] below rural | (20) [women] above rural | (27) [women] below rural | |
---|---|---|---|---|
1 | Lamu - 50.9 | Siaya - 39.9 | Kiambu - 55.8 | Isiolo - 44.4 |
2 | Bungoma - 50.6 | Nyamira - 40.0 | Mombasa - 55.3 | Kilifi - 44.6 |
3 | Baringo - 50.3 | Migori - 40.1 | Uasin Gishu - 55.2 | Kwale - 45.5 |
4 | Nyeri - 49.9 | Kisumu - 40.1 | Kirinyaga - 54.8 | Mandera - 45.5 |
5 | Trans Nzoia - 49.6 | Kitui - 40.3 | Laikipia - 54.5 | Garissa - 45.6 |
Top 5 counties above and below Urban life expectancy - age 20
(12) [men] above urban | (35) [men] below urban | (11) [women] above urban | (36) [women] below urban | |
---|---|---|---|---|
1 | Lamu - 50.9 | Siaya - 39.9 | Kiambu - 55.8 | Isiolo - 44.4 |
2 | Bungoma - 50.6 | Nyamira - 40.0 | Mombasa - 55.3 | Kilifi - 44.6 |
3 | Baringo - 50.3 | Migori - 40.1 | Uasin Gishu - 55.2 | Kwale - 45.5 |
4 | Nyeri - 49.9 | Kisumu - 40.1 | Kirinyaga - 54.8 | Mandera - 45.5 |
5 | Trans Nzoia - 49.6 | Kitui - 40.3 | Laikipia - 54.5 | Garissa - 45.6 |
Top 5 counties where men have higher life expectancy than women - age 20
COUNTY | MALE | FEMALE | |
---|---|---|---|
10 | Isiolo | 45.9 | 44.4 |
Other Statistics - age 20
MALE | FEMALE | |
---|---|---|
count | 47.000000 | 47.000000 |
mean | 44.285106 | 49.887234 |
std | 3.388983 | 3.748137 |
min | 38.700000 | 44.400000 |
25% | 42.300000 | 46.650000 |
50% | 43.000000 | 49.000000 |
75% | 46.750000 | 52.850000 |
max | 51.000000 | 59.600000 |
Code
'age 60') life_expectancy_analysis(
Life Expectancy at age 60
Plot - age 60
Analysis of Life Expectancy at age 60
Top 5 counties with greatest and least life expectancy - age 60
[men] by_county_desc | [men] by_county_asc | [women] by_county_desc | [women] by_county_asc | |
---|---|---|---|---|
1 | Mombasa - 17.7 | Homa Bay - 13.7 | Nyeri - 22.2 | Isiolo - 15.4 |
2 | Lamu - 17.7 | Machakos - 13.7 | Kiambu - 20.2 | Turkana - 15.7 |
3 | Bungoma - 17.6 | Kajiado - 13.7 | Mombasa - 20.0 | Kilifi - 15.9 |
4 | Baringo - 17.4 | Nyandarua - 13.8 | Uasin Gishu - 19.9 | Tana River - 15.9 |
5 | Trans Nzoia - 17.1 | Makueni - 13.8 | Kirinyaga - 19.7 | Marsabit - 16.0 |
Top 5 counties above and below National life expectancy - age 60
(24) [men] above national | (23) [men] below national | (23) [women] above national | (24) [women] below national | |
---|---|---|---|---|
1 | Lamu - 17.7 | Machakos - 13.7 | Kiambu - 20.2 | Turkana - 15.7 |
2 | Bungoma - 17.6 | Kajiado - 13.7 | Mombasa - 20.0 | Kilifi - 15.9 |
3 | Baringo - 17.4 | Makueni - 13.8 | Uasin Gishu - 19.9 | Tana River - 15.9 |
4 | Kakamega - 17.1 | Nyandarua - 13.8 | Kirinyaga - 19.7 | Marsabit - 16.0 |
5 | Trans Nzoia - 17.1 | Siaya - 13.9 | Laikipia - 19.5 | Kwale - 16.2 |
Top 5 counties above and below Rural life expectancy - age 60
(23) [men] above rural | (24) [men] below rural | (20) [women] above rural | (27) [women] below rural | |
---|---|---|---|---|
1 | Lamu - 17.7 | Machakos - 13.7 | Kiambu - 20.2 | Turkana - 15.7 |
2 | Bungoma - 17.6 | Kajiado - 13.7 | Mombasa - 20.0 | Kilifi - 15.9 |
3 | Baringo - 17.4 | Makueni - 13.8 | Uasin Gishu - 19.9 | Tana River - 15.9 |
4 | Kakamega - 17.1 | Nyandarua - 13.8 | Kirinyaga - 19.7 | Marsabit - 16.0 |
5 | Trans Nzoia - 17.1 | Siaya - 13.9 | Laikipia - 19.5 | Kwale - 16.2 |
Top 5 counties above and below Urban life expectancy - age 60
(15) [men] above urban | (32) [men] below urban | (16) [women] above urban | (31) [women] below urban | |
---|---|---|---|---|
1 | Lamu - 17.7 | Kajiado - 13.7 | Kiambu - 20.2 | Turkana - 15.7 |
2 | Bungoma - 17.6 | Machakos - 13.7 | Mombasa - 20.0 | Kilifi - 15.9 |
3 | Baringo - 17.4 | Makueni - 13.8 | Uasin Gishu - 19.9 | Tana River - 15.9 |
4 | Trans Nzoia - 17.1 | Nyandarua - 13.8 | Kirinyaga - 19.7 | Marsabit - 16.0 |
5 | Kakamega - 17.1 | Siaya - 13.9 | Laikipia - 19.5 | Kwale - 16.2 |
Top 5 counties where men have higher life expectancy than women - age 60
COUNTY | MALE | FEMALE | |
---|---|---|---|
10 | Isiolo | 15.7 | 15.4 |
Other Statistics - age 60
MALE | FEMALE | |
---|---|---|
count | 47.000000 | 47.000000 |
mean | 15.014894 | 17.640426 |
std | 1.291271 | 1.496178 |
min | 13.700000 | 15.400000 |
25% | 14.000000 | 16.450000 |
50% | 14.500000 | 17.000000 |
75% | 16.000000 | 18.700000 |
max | 17.700000 | 22.200000 |
Code
'age 80', axis_margin = 0.1) life_expectancy_analysis(
Life Expectancy at age 80
Plot - age 80
20 [ 0.85928444 -0.45533174] 35 [-0.08290397 -0.92990256]
Analysis of Life Expectancy at age 80
Top 5 counties with greatest and least life expectancy - age 80
[men] by_county_desc | [men] by_county_asc | [women] by_county_desc | [women] by_county_asc | |
---|---|---|---|---|
1 | Nyeri - 6.0 | West Pokot - 5.2 | Nyeri - 7.4 | Marsabit - 5.7 |
2 | Mombasa - 5.9 | Tana River - 5.2 | Kiambu - 6.6 | Isiolo - 5.7 |
3 | Bungoma - 5.9 | Garissa - 5.2 | Mombasa - 6.5 | Turkana - 5.7 |
4 | Lamu - 5.9 | Wajir - 5.2 | Uasin Gishu - 6.5 | Homa Bay - 5.8 |
5 | Baringo - 5.9 | Mandera - 5.2 | Kirinyaga - 6.5 | Siaya - 5.8 |
Top 5 counties above and below National life expectancy - age 80
(7) [men] above national | (40) [men] below national | (15) [women] above national | (32) [women] below national | |
---|---|---|---|---|
1 | Mombasa - 5.9 | Tana River - 5.2 | Kiambu - 6.6 | Isiolo - 5.7 |
2 | Lamu - 5.9 | Garissa - 5.2 | Mombasa - 6.5 | Turkana - 5.7 |
3 | Baringo - 5.9 | Wajir - 5.2 | Kirinyaga - 6.5 | Homa Bay - 5.8 |
4 | Bungoma - 5.9 | Mandera - 5.2 | Uasin Gishu - 6.5 | Siaya - 5.8 |
5 | Trans Nzoia - 5.8 | Narok - 5.3 | Embu - 6.4 | Migori - 5.9 |
Top 5 counties above and below Rural life expectancy - age 80
(23) [men] above rural | (24) [men] below rural | (8) [women] above rural | (39) [women] below rural | |
---|---|---|---|---|
1 | Mombasa - 5.9 | Garissa - 5.2 | Kiambu - 6.6 | Isiolo - 5.7 |
2 | Lamu - 5.9 | Wajir - 5.2 | Mombasa - 6.5 | Turkana - 5.7 |
3 | Bungoma - 5.9 | Mandera - 5.2 | Kirinyaga - 6.5 | Homa Bay - 5.8 |
4 | Baringo - 5.9 | West Pokot - 5.2 | Uasin Gishu - 6.5 | Siaya - 5.8 |
5 | Kakamega - 5.8 | Kwale - 5.3 | Embu - 6.4 | Migori - 5.9 |
Top 5 counties above and below Urban life expectancy - age 80
(12) [men] above urban | (35) [men] below urban | (5) [women] above urban | (42) [women] below urban | |
---|---|---|---|---|
1 | Mombasa - 5.9 | Garissa - 5.2 | Kiambu - 6.6 | Isiolo - 5.7 |
2 | Lamu - 5.9 | Wajir - 5.2 | Mombasa - 6.5 | Turkana - 5.7 |
3 | Baringo - 5.9 | Mandera - 5.2 | Kirinyaga - 6.5 | Homa Bay - 5.8 |
4 | Bungoma - 5.9 | West Pokot - 5.2 | Uasin Gishu - 6.5 | Siaya - 5.8 |
5 | Trans Nzoia - 5.8 | Kwale - 5.3 | None | Migori - 5.9 |
Other Statistics - age 80
MALE | FEMALE | |
---|---|---|
count | 47.000000 | 47.000000 |
mean | 5.487234 | 6.176596 |
std | 0.223234 | 0.281466 |
min | 5.200000 | 5.700000 |
25% | 5.300000 | 6.000000 |
50% | 5.400000 | 6.200000 |
75% | 5.650000 | 6.300000 |
max | 6.000000 | 7.400000 |
Insights
- The rural and national life expectancy is are close, which confirms that majority of Kenyans lives in rural areas.
- Men and Women of Nyeri county Have the greatest overall life expectancy, in all ranges.
- Isiolo county is the only county men below 80 years live longer than women.
Disclaimer: For information only. Accuracy or completeness not guaranteed. Illegal use prohibited. Not professional advice or solicitation. Read more: /terms-of-service
Footnotes / Citations / References
Reuse
Citation
@misc{kabui2025,
author = {{Kabui, Charles}},
title = {Life {Expectancy} by {Age,} {Gender} and {Counties} in
{Kenya}},
date = {2025-03-18},
url = {https://toknow.ai/posts/life-expectancy-age-gender-and-counties-in-kenya/index.html},
langid = {en-GB}
}