jiyachachan commited on
Commit
f5bd455
·
verified ·
1 Parent(s): 5114abc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -48,7 +48,7 @@ top_countries = filtered_data.nlargest(num_countries, "gdp_per_capita")
48
  scatter_plot = alt.Chart(top_countries).mark_circle(size=60).encode(
49
  x=alt.X("gdp_per_capita:Q", scale=alt.Scale(type="log"), title="GDP per Capita (Log Scale)"),
50
  y=alt.Y("child_mortality:Q", title="Child Mortality (per 1,000 live births)"),
51
- color="country:N",
52
  tooltip=["country", "gdp_per_capita", "child_mortality"]
53
  ).properties(
54
  title=f"Relationship Between GDP Per Capita and Child Mortality ({year})",
@@ -62,10 +62,10 @@ regression_line = scatter_plot.transform_regression(
62
  ).mark_line(color="red")
63
 
64
  # Combine scatter plot and regression line
65
- #final_chart = scatter_plot + regression_line
66
 
67
  # Display chart in Streamlit
68
- st.altair_chart(scatter_plot, use_container_width=True)
69
 
70
 
71
  st.text("To build the observatory, I began by preparing the dataset, which involved merging child mortality and GDP per capita data based on common fields: country and year. I ensured that the data was cleaned and formatted correctly, converting numerical fields like child_mortality and gdp_per_capita to numeric types and handling missing values by dropping rows with invalid entries. Once the data was ready, I created initial static visualizations using Altair to explore the relationship between GDP per capita and child mortality. The chart shows the relationship between GDP per capita and child mortality rates, highlighting an inverse trend where higher GDP per capita generally corresponds to lower child mortality. Building on this foundation, I added interactivity through Streamlit, allowing users to dynamically filter the dataset by year and select the number of countries to display. To enhance the visual analysis, I overlaid a regression line on the scatter plot, which provides a clear representation of trends. The app's functionality was refined iteratively, incorporating sliders for user interaction and tooltips for exploring country-specific data points.")
 
48
  scatter_plot = alt.Chart(top_countries).mark_circle(size=60).encode(
49
  x=alt.X("gdp_per_capita:Q", scale=alt.Scale(type="log"), title="GDP per Capita (Log Scale)"),
50
  y=alt.Y("child_mortality:Q", title="Child Mortality (per 1,000 live births)"),
51
+ color=alt.Color("country:N"),
52
  tooltip=["country", "gdp_per_capita", "child_mortality"]
53
  ).properties(
54
  title=f"Relationship Between GDP Per Capita and Child Mortality ({year})",
 
62
  ).mark_line(color="red")
63
 
64
  # Combine scatter plot and regression line
65
+ final_chart = scatter_plot + regression_line
66
 
67
  # Display chart in Streamlit
68
+ st.altair_chart(final_chart, use_container_width=True)
69
 
70
 
71
  st.text("To build the observatory, I began by preparing the dataset, which involved merging child mortality and GDP per capita data based on common fields: country and year. I ensured that the data was cleaned and formatted correctly, converting numerical fields like child_mortality and gdp_per_capita to numeric types and handling missing values by dropping rows with invalid entries. Once the data was ready, I created initial static visualizations using Altair to explore the relationship between GDP per capita and child mortality. The chart shows the relationship between GDP per capita and child mortality rates, highlighting an inverse trend where higher GDP per capita generally corresponds to lower child mortality. Building on this foundation, I added interactivity through Streamlit, allowing users to dynamically filter the dataset by year and select the number of countries to display. To enhance the visual analysis, I overlaid a regression line on the scatter plot, which provides a clear representation of trends. The app's functionality was refined iteratively, incorporating sliders for user interaction and tooltips for exploring country-specific data points.")