streamlit / app.py
tharu22's picture
changed con
1ae8791
raw
history blame
1.86 kB
import streamlit as st
import pandas as pd
# File path (modify as needed)
file_path = "world_population.csv"
# Load dataset
df = pd.read_csv(file_path)
# Streamlit UI
st.title("🌍 World Population Dashboard")
# Sidebar filter
st.sidebar.header("Select a Continent")
continents = df["Continent"].unique()
selected_continent = st.sidebar.selectbox("Choose Continent:", continents)
# Processing Data
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
# Display results for selected continent
if selected_continent:
st.header(f"🌎 {selected_continent} Statistics")
# Population Metrics
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}")
# Other Metrics
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")
# Footer
st.markdown("πŸš€ Built with Streamlit")