changed con
Browse files
app.py
CHANGED
@@ -1,50 +1,44 @@
|
|
1 |
import streamlit as st
|
2 |
-
import requests
|
3 |
import pandas as pd
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
#
|
15 |
-
st.
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
)
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
st.metric("Population Density", f"{data['continent_population_density']:.2f}")
|
38 |
-
st.subheader("Population Highlights")
|
39 |
-
st.write(
|
40 |
-
f"Max Population :{data['max_population']['country']} "
|
41 |
-
f"({data['max_population']['population']:,})"
|
42 |
-
)
|
43 |
-
# Country with min population
|
44 |
-
st.write(
|
45 |
-
f"Min Population:{data['min_population']['country']} "
|
46 |
-
f"({data['min_population']['population']:,})"
|
47 |
-
)
|
48 |
-
else:
|
49 |
-
# Handle errors
|
50 |
-
st.error(f"Error: {response.json()['detail']}")
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import pandas as pd
|
3 |
|
4 |
+
# File path (modify as needed)
|
5 |
+
file_path = "world_population.csv"
|
6 |
+
|
7 |
+
# Load dataset
|
8 |
+
df = pd.read_csv(file_path)
|
9 |
+
|
10 |
+
# Streamlit UI
|
11 |
+
st.title("π World Population Dashboard")
|
12 |
+
|
13 |
+
# Sidebar filter
|
14 |
+
st.sidebar.header("Select a Continent")
|
15 |
+
continents = df["Continent"].unique()
|
16 |
+
selected_continent = st.sidebar.selectbox("Choose Continent:", continents)
|
17 |
+
|
18 |
+
# Processing Data
|
19 |
+
max_population = df.groupby("Continent")["Population"].max()
|
20 |
+
min_population = df.groupby("Continent")["Population"].min()
|
21 |
+
max_country = df.loc[df.groupby("Continent")["Population"].idxmax(), ["Continent", "Country"]]
|
22 |
+
min_country = df.loc[df.groupby("Continent")["Population"].idxmin(), ["Continent", "Country"]]
|
23 |
+
average_population = df.groupby("Continent")["Population"].mean()
|
24 |
+
total_area = df.groupby("Continent")["Area"].sum()
|
25 |
+
total_population = df.groupby("Continent")["Population"].sum()
|
26 |
+
population_density = total_population / total_area
|
27 |
+
|
28 |
+
# Display results for selected continent
|
29 |
+
if selected_continent:
|
30 |
+
st.header(f"π {selected_continent} Statistics")
|
31 |
+
|
32 |
+
# Population Metrics
|
33 |
+
st.metric("π Maximum Population", f"{max_population[selected_continent]:,} ({max_country[max_country['Continent'] == selected_continent]['Country'].values[0]})")
|
34 |
+
st.metric("π Minimum Population", f"{min_population[selected_continent]:,} ({min_country[min_country['Continent'] == selected_continent]['Country'].values[0]})")
|
35 |
+
st.metric("π Average Population", f"{average_population[selected_continent]:,.0f}")
|
36 |
|
37 |
+
# Other Metrics
|
38 |
+
st.metric("π Total Area", f"{total_area[selected_continent]:,} sq km")
|
39 |
+
st.metric("π₯ Total Population", f"{total_population[selected_continent]:,}")
|
40 |
+
st.metric("π Population Density", f"{population_density[selected_continent]:.2f} people/sq km")
|
41 |
+
|
42 |
+
# Footer
|
43 |
+
st.markdown("π Built with Streamlit")
|
44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|