|
import streamlit as st |
|
import pandas as pd |
|
|
|
|
|
file_path = "world_population.csv" |
|
|
|
|
|
df = pd.read_csv(file_path) |
|
|
|
|
|
st.title("π World Population Dashboard") |
|
|
|
|
|
st.sidebar.header("Select a Continent") |
|
continents = df["Continent"].unique() |
|
selected_continent = st.sidebar.selectbox("Choose Continent:", continents) |
|
|
|
|
|
max_population = df.groupby("Continent")["Population"].max() |
|
min_population = df.groupby("Continent")["Population"].min() |
|
max_country = df.loc[df.groupby("Continent")["Population"].idxmax(), ["Continent", "Country"]] |
|
min_country = df.loc[df.groupby("Continent")["Population"].idxmin(), ["Continent", "Country"]] |
|
average_population = df.groupby("Continent")["Population"].mean() |
|
total_area = df.groupby("Continent")["Area"].sum() |
|
total_population = df.groupby("Continent")["Population"].sum() |
|
population_density = total_population / total_area |
|
|
|
|
|
if selected_continent: |
|
st.header(f"π {selected_continent} Statistics") |
|
|
|
|
|
st.metric("π Maximum Population", f"{max_population[selected_continent]:,} ({max_country[max_country['Continent'] == selected_continent]['Country'].values[0]})") |
|
st.metric("π Minimum Population", f"{min_population[selected_continent]:,} ({min_country[min_country['Continent'] == selected_continent]['Country'].values[0]})") |
|
st.metric("π Average Population", f"{average_population[selected_continent]:,.0f}") |
|
|
|
|
|
st.metric("π Total Area", f"{total_area[selected_continent]:,} sq km") |
|
st.metric("π₯ Total Population", f"{total_population[selected_continent]:,}") |
|
st.metric("π Population Density", f"{population_density[selected_continent]:.2f} people/sq km") |
|
|
|
|
|
st.markdown("π Built with Streamlit") |
|
|
|
|