Spaces:
Sleeping
Sleeping
Create Child Mortality vs Daily Income.py (#3)
Browse files- Create Child Mortality vs Daily Income.py (d1a7338220465be5b579d574330ec6236ffea742)
Co-authored-by: Ji Eun Kim <jieunk3@users.noreply.huggingface.co>
pages/Child Mortality vs Daily Income.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import altair as alt
|
| 4 |
+
|
| 5 |
+
income_df = pd.read_csv('https://huggingface.co/spaces/jiyachachan/fp2/resolve/main/mincpcap_cppp.csv')
|
| 6 |
+
mortality_df = pd.read_csv('https://huggingface.co/spaces/jiyachachan/fp2/resolve/main/child_mortality_0_5_year_olds_dying_per_1000_born.csv')
|
| 7 |
+
|
| 8 |
+
income_long = pd.melt(income_df, id_vars=['country'], var_name='year', value_name='income')
|
| 9 |
+
mortality_long = pd.melt(mortality_df, id_vars=['country'], var_name='year', value_name='mortality')
|
| 10 |
+
|
| 11 |
+
income_long['year'] = income_long['year'].astype(int)
|
| 12 |
+
mortality_long['year'] = mortality_long['year'].astype(int)
|
| 13 |
+
|
| 14 |
+
yay = pd.merge(income_long, mortality_long, on=['country', 'year'])
|
| 15 |
+
|
| 16 |
+
yer = yay.dropna()
|
| 17 |
+
yer = yer[yer["year"] <= 2024]
|
| 18 |
+
|
| 19 |
+
st.title("Child Mortality vs Daily Income")
|
| 20 |
+
|
| 21 |
+
filtered_yer = yer[yer["year"] == yeyear]
|
| 22 |
+
|
| 23 |
+
scatter_plot = alt.Chart(filtered_yer).mark_circle(size=60).encode(
|
| 24 |
+
x=alt.X('income', title='Daily Income (USD)', scale=alt.Scale(type='log')),
|
| 25 |
+
y=alt.Y('mortality', title='Child Mortality (per 1,000)'),
|
| 26 |
+
color='country',
|
| 27 |
+
tooltip=['country', 'year', 'income', 'mortality']
|
| 28 |
+
).properties(
|
| 29 |
+
width=700,
|
| 30 |
+
height=500,
|
| 31 |
+
title=f"Child Mortality vs Daily Income in {yeyear}"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
st.altair_chart(scatter_plot, use_container_width=True)
|
| 35 |
+
|
| 36 |
+
st.text("The interactive scatterplot above displays Child Mortality versus Daily Income from 24 countries. The interactive slider allows the user to choose a year where the earliest year is 1800 and the maximum year is 2024. The x-axis is represented by daily income (USD) set to a logarithmic scale for better visualization of larger income ranges, and the y-axis is represented by child mortality (per 1,000). Each country is assigned a unique color and we incorporate a hover tooltip to show the country, year, income, and mortality rate for a specific data point.")
|