diff --git a/app/main.py b/app/main.py
index 765df27f..df97e333 100644
--- a/app/main.py
+++ b/app/main.py
@@ -2,19 +2,21 @@ import pandas as pd
import plotly.express as px
import streamlit as st
import os
+import numpy as np
data_location = os.path.realpath(
os.path.join(os.getcwd(), 'data'))
-st.set_page_config(page_title='Dashboard',
+st.set_page_config(page_title='Azerbaijan Suicide Data',
page_icon=':bar_chart:',
layout='wide')
-data_age = pd.read_excel(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'), sheet_name='age')
+####################################### Data by Age #######################################
+
data_year = pd.read_excel(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'), sheet_name='year')
-st.sidebar.header('Filter:')
+st.sidebar.header('Data by Year:')
data_year_filter_year = st.sidebar.multiselect(
'Select Year:',
options = data_year['Year'].unique(),
@@ -28,53 +30,114 @@ data_year_selection = data_year.query(
both_sexes = [float(d[:d.find(' ')]) for d in data_year_selection.Both_sexes]
both_sexes_len = len(both_sexes)
-average_both_sexes = sum(both_sexes) / (both_sexes_len if both_sexes_len else 1)
+average_both_sexes_year = sum(both_sexes) / (both_sexes_len if both_sexes_len else 1)
male = [float(d[:d.find(' ')]) for d in data_year_selection.Male]
male_len = len(male)
-average_male = sum(male) / (male_len if male_len else 1)
+average_male_year = sum(male) / (male_len if male_len else 1)
female = [float(d[:d.find(' ')]) for d in data_year_selection.Female]
female_len = len(female)
-average_female = sum(female) / (female_len if female_len else 1)
+average_female_year = sum(female) / (female_len if female_len else 1)
df_line_graph = pd.DataFrame(
{'Year': data_year_selection.Year, 'Both Sexes': both_sexes, 'Male': male, 'Female': female})
-st.title('
Azerbaijan Suicide Data (2000-2019)
', 1)
+st.title('Azerbaijan Suicide Data by Year(2000-2019)
', 1)
st.dataframe(data_year_selection)
-st.title('Dashboard
', 1)
+st.title('Dashboard by Year
', 1)
dashboard_column1, dashboard_column2 = st.columns([1, 2])
with dashboard_column1:
- st.subheader('Averages')
- st.markdown(f'#### Average of Both Sexes: _{round(average_both_sexes, 2)}_')
- st.markdown(f'#### Average of Male: _{round(average_male, 2)}_')
- st.markdown(f'#### Average of Female: _{round(average_female, 2)}_')
+ st.subheader('Averages by Years')
+ st.markdown(f'#### Average of Both Sexes: _{round(average_both_sexes_year, 2)}_')
+ st.markdown(f'#### Average of Male: _{round(average_male_year, 2)}_')
+ st.markdown(f'#### Average of Female: _{round(average_female_year, 2)}_')
with dashboard_column2:
- if average_both_sexes > 0:
- bar_graph = px.bar(x=['Both Sexes', 'Male', 'Female'], y=[average_both_sexes, average_male, average_female])
+ if average_both_sexes_year > 0:
+ bar_graph = px.bar(x=['Both Sexes', 'Male', 'Female'], y=[average_both_sexes_year, average_male_year, average_female_year])
st.plotly_chart(bar_graph)
if len(df_line_graph) > 1:
- st.title('Gender Line Graph
', 1)
+ st.title('Gender Line Graph by Year
', 1)
line_graph_column1, line_graph_column2 = st.columns([1, 7])
with line_graph_column1:
column_list = []
st.markdown(' ')
- both_sexes_check_box = st.checkbox('Both Sexes', value=1)
- male_check_box = st.checkbox('Male', value=1)
- female_check_box = st.checkbox('Female', value=1)
- if both_sexes_check_box: column_list.append('Both Sexes')
- if male_check_box: column_list.append('Male')
- if female_check_box: column_list.append('Female')
+ both_sexes_check_box_year = st.checkbox('Both Sexes', value=1, key='both_sexes_check_box_year')
+ male_check_box_year = st.checkbox('Male', value=1, key='male_check_box_year')
+ female_check_box_year = st.checkbox('Female', value=1, key='female_check_box_year')
+ if both_sexes_check_box_year: column_list.append('Both Sexes')
+ if male_check_box_year: column_list.append('Male')
+ if female_check_box_year: column_list.append('Female')
with line_graph_column2:
if column_list:
line_graph = px.line(df_line_graph, x='Year', y=column_list)
st.plotly_chart(line_graph)
+####################################### Data by Age #######################################
+
+st.title('Azerbaijan Suicide Data by Age (2019)
', 1)
+
+data_age = pd.read_excel(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'), sheet_name='age')\
+ .loc[::-1].reset_index(drop=True)
+
+st.sidebar.header('Data by Age:')
+data_age_filter_age = st.sidebar.multiselect(
+ 'Select Age:',
+ options = data_age['Age'].unique(),
+ default = data_age['Age'].unique()
+)
+
+data_age_selection = data_age.query(
+ 'Age == @data_age_filter_age'
+)
+
+average_both_sexes_age = np.average(data_age_selection.Both_sexes)
+average_male_age = np.average(data_age_selection.Male)
+average_female_age = np.average(data_age_selection.Female)
+
+st.dataframe(data_age_selection)
+
+st.title('Dashboard by Age
', 1)
+dashboard_column1, dashboard_column2 = st.columns([1, 2])
+
+with dashboard_column1:
+ st.subheader('Averages by Age')
+ st.markdown(f'#### Average of Both Sexes: _{round(average_both_sexes_age, 2)}_')
+ st.markdown(f'#### Average of Male: _{round(average_male_age, 2)}_')
+ st.markdown(f'#### Average of Female: _{round(average_female_age, 2)}_')
+
+with dashboard_column2:
+ if average_both_sexes_age > 0:
+ bar_graph = px.bar(x=['Both Sexes', 'Male', 'Female'], y=[average_both_sexes_age, average_male_age, average_female_age])
+ st.plotly_chart(bar_graph)
+
+
+if 1:
+ st.title('Gender Line Graph by Age
', 1)
+ line_graph_column1, line_graph_column2 = st.columns([1, 7])
+ with line_graph_column1:
+ column_list = []
+ st.markdown(' ')
+ both_sexes_check_box_age = st.checkbox('Both Sexes', value=1, key='both_sexes_check_box_age')
+ male_check_box_age = st.checkbox('Male', value=1, key='male_check_box_age')
+ female_check_box_age = st.checkbox('Female', value=1, key='female_check_box_age')
+ if both_sexes_check_box_age: column_list.append('Both Sexes')
+ if male_check_box_age: column_list.append('Male')
+ if female_check_box_age: column_list.append('Female')
+
+ with line_graph_column2:
+ print(column_list)
+ if column_list:
+ data_age_line_graph = data_age.copy()
+ data_age_line_graph.columns = ['Age', 'Both Sexes', 'Male', 'Female']
+ line_graph = px.line(data_age_line_graph, x='Age', y=column_list)
+ st.plotly_chart(line_graph)
+
+
hide_st_style = """
\n",
+ "\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Age | \n",
+ " Both_sexes | \n",
+ " Male | \n",
+ " Female | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 15-24 | \n",
+ " 4.00 | \n",
+ " 6.38 | \n",
+ " 1.34 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 25-34 | \n",
+ " 4.89 | \n",
+ " 8.43 | \n",
+ " 1.36 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 35-44 | \n",
+ " 5.42 | \n",
+ " 9.42 | \n",
+ " 1.50 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 45-54 | \n",
+ " 5.25 | \n",
+ " 9.14 | \n",
+ " 1.73 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 55-64 | \n",
+ " 5.70 | \n",
+ " 9.50 | \n",
+ " 2.35 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 65-74 | \n",
+ " 6.82 | \n",
+ " 10.93 | \n",
+ " 3.57 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 75-84 | \n",
+ " 10.40 | \n",
+ " 15.22 | \n",
+ " 7.36 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 85+ | \n",
+ " 23.97 | \n",
+ " 38.35 | \n",
+ " 16.87 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ ""
+ ],
+ "text/plain": [
+ " Age Both_sexes Male Female\n",
+ "0 15-24 4.00 6.38 1.34\n",
+ "1 25-34 4.89 8.43 1.36\n",
+ "2 35-44 5.42 9.42 1.50\n",
+ "3 45-54 5.25 9.14 1.73\n",
+ "4 55-64 5.70 9.50 2.35\n",
+ "5 65-74 6.82 10.93 3.57\n",
+ "6 75-84 10.40 15.22 7.36\n",
+ "7 85+ 23.97 38.35 16.87"
+ ]
+ },
+ "execution_count": 66,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data_age"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "data_age = data_age.loc[::-1].reset_index(drop=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([['85+', 23.97, 38.35, 16.87],\n",
+ " ['75-84', 10.4, 15.22, 7.36],\n",
+ " ['65-74', 6.82, 10.93, 3.57],\n",
+ " ['55-64', 5.7, 9.5, 2.35],\n",
+ " ['45-54', 5.25, 9.14, 1.73],\n",
+ " ['35-44', 5.42, 9.42, 1.5],\n",
+ " ['25-34', 4.89, 8.43, 1.36],\n",
+ " ['15-24', 4.0, 6.38, 1.34]], dtype=object)"
+ ]
+ },
+ "execution_count": 59,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data_age.values"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 45,
diff --git a/poetry.lock b/poetry.lock
index 7f4b4964..a2ae4f74 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1265,7 +1265,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
[metadata]
lock-version = "1.1"
python-versions = "^3.10"
-content-hash = "16c117b957e6d8453510db37d604102150a97579357606d82203d30a12eed065"
+content-hash = "37f9f4e41bf6ad2bd5b77b2694cf53f01ced08ff1d3d8b55cfed27728827b539"
[metadata.files]
altair = [
diff --git a/pyproject.toml b/pyproject.toml
index 8721967d..70c3c2f0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,6 +10,7 @@ streamlit = "^1.9.0"
plotly = "^5.8.0"
pytest = "^7.1.2"
openpyxl = "^3.0.10"
+numpy = "^1.22.4"
[tool.poetry.dev-dependencies]