File size: 1,864 Bytes
0f15b2f
 
 
1ae8791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b4ac00
1ae8791
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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")