File size: 2,743 Bytes
fe475ff
 
 
 
 
 
5191254
 
 
 
 
 
 
 
 
fe475ff
 
5191254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe475ff
5191254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
src_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "frontend"))
sys.path.append(src_directory)
import streamlit as st
import streamlit_functions
import pandas as pd

def load_data(file):
    try:
        data = pd.read_csv(file)
        return data
    except Exception as e:
        st.error(f"Error loading file: {e}")
        return None

st.title("World Population Data")
st.sidebar.title("Navigation")

choosen_data = streamlit_functions.choose_data_to_view(st)

if choosen_data == "Show All Continents":
    option = choosen_data.replace(" ", "")
    streamlit_functions.display_contents(option, st)

elif choosen_data == "Show All Countries":
    option = choosen_data.replace(" ", "")
    streamlit_functions.display_contents(option, st)

elif choosen_data == "Show Continent Stats":
    streamlit_functions.display_stats(st, choosen_data)

elif choosen_data == "Show Country Stats":
    streamlit_functions.display_stats(st, choosen_data)

elif choosen_data == "Show Continent Wise Data":
    clean_choosen_data = choosen_data.replace(" ", "")
    attribute = streamlit_functions.choose_attribute_to_view(st)
    if attribute in ["Population","Area"]:
        option = f"{clean_choosen_data}/{attribute}"
        streamlit_functions.display_contents(option,st)

elif choosen_data == "Show Country Data":
    clean_choosen_data = choosen_data.replace(" ", "")
    country_list = streamlit_functions.get_list("ShowAllCountries")
    choosen_country = streamlit_functions.choose_data_from_list(st,country_list)
    clean_country = choosen_country.replace(" ","").capitalize()
    attribute = streamlit_functions.choose_attribute_to_view(st)
    if attribute in ["Population","Area"]:
        option = f"{clean_choosen_data}/{clean_country}/{attribute}"
        streamlit_functions.display_contents(option,st)

elif choosen_data == "Upload Custom CSV":
    uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type=['csv'])
    
    if uploaded_file is not None:
        data = load_data(uploaded_file)
        
        if data is not None:
            st.write("Data Preview:", data.head())
            
            if "Continent" in data.columns and "Population" in data.columns:
                continent_data = data.groupby("Continent")["Population"].sum().reset_index()
                st.write("Continent-wise Population Summary:", continent_data)
            else:
                st.warning("The uploaded CSV does not contain 'Continent' or 'Population' columns.")
        
        else:
            st.warning("There was an error loading the file. Please check the format and try again.")
else:
    st.write("Please choose an option from the sidebar to view the data.")