moiralala commited on
Commit
58a4989
·
verified ·
1 Parent(s): 708a521

upload child mortality & life expectancy file

Browse files
Files changed (1) hide show
  1. pages/mortality_life.py +99 -0
pages/mortality_life.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import altair as alt
4
+
5
+ child_mortality = pd.read_csv("../child_mortality_0_5_year_olds_dying_per_1000_born.csv")
6
+ life_expectancy = pd.read_csv("../life_expectancy.csv")
7
+
8
+ st.title("Interactive Observatory: Child Mortality & Life Expectancy")
9
+ st.write("""
10
+ For this analysis, I selected Argentina, Australia, China, India, South Africa, the UK,
11
+ and the USA as representative countries for different global regions. These countries
12
+ highlight diverse economic, social, and historical contexts, making them ideal for
13
+ observing trends in child mortality and life expectancy. The time period of 1900 to
14
+ 2024 was chosen as it encompasses rapid global industrialization, the rise of modern
15
+ medicine, and recent advancements in healthcare and living standards, while also including
16
+ years with limited historical data to provide a broader context.
17
+ """)
18
+
19
+ countries = list(child_mortality['country'].unique())
20
+ selected_countries = st.sidebar.multiselect("Select Countries", countries, default=["Argentina", "Australia", "China", "India", "South Africa", "UK", "USA"])
21
+ year_range = st.sidebar.slider("Select Year Range", 1900, 2024, (1900, 2024))
22
+
23
+ filtered_mortality = child_mortality[child_mortality['country'].isin(selected_countries)]
24
+ filtered_expectancy = life_expectancy[life_expectancy['country'].isin(selected_countries)]
25
+ years = [str(year) for year in range(year_range[0], year_range[1] + 1)]
26
+ filtered_mortality = filtered_mortality[['country'] + years]
27
+ filtered_expectancy = filtered_expectancy[['country'] + years]
28
+
29
+ def melt_dataframe(df, value_name):
30
+ df_melted = df.melt(id_vars=["country"], var_name="year", value_name=value_name)
31
+ df_melted["year"] = df_melted["year"].astype(int)
32
+ return df_melted
33
+
34
+ mortality_melted = melt_dataframe(filtered_mortality, "Child Mortality")
35
+ expectancy_melted = melt_dataframe(filtered_expectancy, "Life Expectancy")
36
+
37
+ # Chart 1: Child Mortality Trends
38
+ st.subheader("Chart 1: Child Mortality Trends")
39
+ st.write("""
40
+ This chart reveals significant regional disparities in child mortality rates across the
41
+ selected countries. For instance, India and South Africa initially exhibit much higher
42
+ mortality rates compared to developed nations like the USA and the UK, reflecting disparities
43
+ in healthcare access. Notably, the chart captures periods of global crises such as pandemics
44
+ or wars, where temporary spikes in child mortality rates can be observed, such as in South
45
+ Africa during the mid-20th century. Over time, all countries demonstrate a marked decline,
46
+ indicating progress in global health and development.
47
+ """)
48
+
49
+ mortality_chart = alt.Chart(mortality_melted).mark_line().encode(
50
+ x=alt.X("year:O", title="Year"),
51
+ y=alt.Y("Child Mortality:Q", title="Child Mortality (0–5 years per 1000 births)"),
52
+ color="country:N"
53
+ ).properties(width=700, height=400)
54
+
55
+ st.altair_chart(mortality_chart)
56
+
57
+ # Chart 2: Life Expectancy Trends
58
+ st.subheader("Chart 2: Life Expectancy Trends")
59
+ st.write("""
60
+ This visualization shows how life expectancy has improved across all regions, with
61
+ countries like the UK and the USA maintaining consistently higher life expectancy,
62
+ while developing nations such as India and South Africa only recently catching up.
63
+ However, fluctuations are visible, notably during the 1918 influenza pandemic and
64
+ the global conflicts of the 20th century, where life expectancy briefly plummeted.
65
+ Interestingly, the sharp rise in life expectancy in countries like China during the
66
+ mid-20th century reflects public health reforms and economic growth.
67
+ """)
68
+
69
+ expectancy_chart = alt.Chart(expectancy_melted).mark_line().encode(
70
+ x=alt.X("year:O", title="Year"),
71
+ y=alt.Y("Life Expectancy:Q", title="Life Expectancy at Birth"),
72
+ color="country:N"
73
+ ).properties(width=700, height=400)
74
+
75
+ st.altair_chart(expectancy_chart)
76
+
77
+ # Chart 3: Child Mortality vs. Life Expectancy
78
+ st.subheader("Chart 3: Child Mortality vs. Life Expectancy")
79
+ st.write("""
80
+ This scatter plot illustrates the strong inverse relationship between child mortality
81
+ rates and life expectancy at birth, underscoring how advancements in healthcare,
82
+ nutrition, and living conditions improve both indicators simultaneously. A particularly
83
+ striking observation is how the data for countries like India and South Africa forms a
84
+ steep curve, signifying rapid improvements in life expectancy as child mortality declines.
85
+ Developed nations such as Australia and the USA show a plateau in the later stages, where
86
+ child mortality rates are already low, and life expectancy improvements are incremental.
87
+ The trajectory of China’s data during the mid-20th century highlights a rapid transition,
88
+ likely due to systemic public health efforts.
89
+ """)
90
+
91
+ merged_data = pd.merge(mortality_melted, expectancy_melted, on=["country", "year"])
92
+ scatter_chart = alt.Chart(merged_data).mark_circle(size=60).encode(
93
+ x=alt.X("Life Expectancy:Q", title="Life Expectancy at Birth"),
94
+ y=alt.Y("Child Mortality:Q", title="Child Mortality (0–5 years per 1000 births)"),
95
+ color="country:N",
96
+ tooltip=["country", "year", "Child Mortality", "Life Expectancy"]
97
+ ).properties(width=700, height=400)
98
+
99
+ st.altair_chart(scatter_chart)