Spaces:
Sleeping
Sleeping
Create income.py (#8)
Browse files- Create income.py (1cd09d9f7236942fedbb7be76523a689a16c6f8f)
Co-authored-by: Ji Eun Kim <jieunk3@users.noreply.huggingface.co>
- pages/income.py +36 -0
pages/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 Visualization")
|
| 20 |
+
|
| 21 |
+
yeyear = st.slider("Select a Year", min_value=yer["year"].min(), max_value=2024, value=2024)
|
| 22 |
+
|
| 23 |
+
filtered_yer = yer[yer["year"] == yeyear]
|
| 24 |
+
|
| 25 |
+
scatter_plot = alt.Chart(filtered_yer).mark_circle(size=60).encode(
|
| 26 |
+
x=alt.X('income', title='Daily Income (USD)', scale=alt.Scale(type='log')),
|
| 27 |
+
y=alt.Y('mortality', title='Child Mortality (per 1,000)'),
|
| 28 |
+
color='country',
|
| 29 |
+
tooltip=['country', 'year', 'income', 'mortality']
|
| 30 |
+
).properties(
|
| 31 |
+
width=700,
|
| 32 |
+
height=500,
|
| 33 |
+
title=f"Child Mortality vs Daily Income in {yeyear}"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
st.altair_chart(scatter_plot, use_container_width=True)
|