mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-01 14:07:48 +00:00
Version 0.1
Added sidebar, Dashboard, Line Graph
This commit is contained in:
63
app/main.py
63
app/main.py
@ -7,14 +7,65 @@ import os
|
||||
data_location = os.path.realpath(
|
||||
os.path.join(os.getcwd(), 'data'))
|
||||
|
||||
# st.set_page_config(page_title='Dashboard',
|
||||
# page_icon=':bar_chart:',
|
||||
# layout='wide')
|
||||
st.set_page_config(page_title='Dashboard',
|
||||
page_icon=':bar_chart:',
|
||||
layout='wide')
|
||||
|
||||
# df = pd.read_csv("C:\\Users\\shahs\\Desktop\\Player_piece_sac_data.csv")
|
||||
data_age = pd.read_excel(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'), sheet_name='age')
|
||||
data_year = pd.read_excel(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'), sheet_name='year')
|
||||
|
||||
# st.dataframe(df)
|
||||
st.sidebar.header('Filter:')
|
||||
data_year_filter_year = st.sidebar.multiselect(
|
||||
'Select Year:',
|
||||
options = data_year['Year'].unique(),
|
||||
default = data_year['Year'].unique()
|
||||
)
|
||||
|
||||
|
||||
data_year_selection = data_year.query(
|
||||
'Year == @data_year_filter_year'
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
|
||||
df_line_graph = pd.DataFrame(
|
||||
{'Year': data_year_selection.Year, 'Both Sexes': both_sexes, 'Male': male, 'Female': female})
|
||||
|
||||
st.title('<h5>Azerbaijan Suicide Data (2000-2019)</h5>', 1)
|
||||
st.dataframe(data_year_selection)
|
||||
|
||||
st.title('<h1>Dashboard</h1>', 1)
|
||||
|
||||
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)}_')
|
||||
|
||||
if len(df_line_graph) > 1:
|
||||
st.title('<h1>Gender Line Graph</h1>', 1)
|
||||
x, y = st.columns([1, 7])
|
||||
with x:
|
||||
column_list = []
|
||||
st.markdown(' ')
|
||||
# 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')
|
||||
|
||||
with y:
|
||||
if column_list:
|
||||
line_graph = px.line(df_line_graph, x='Year', y=column_list)
|
||||
st.plotly_chart(line_graph)
|
||||
|
||||
# print(os.path.join(data_location, 'azerbaijan_suicide_data.xlsx'))
|
218
app/test.ipynb
218
app/test.ipynb
@ -2,16 +2,17 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd"
|
||||
"import pandas as pd\n",
|
||||
"import plotly.express as px"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -21,116 +22,131 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data_age"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"test_male = [float(d[:d.find(' ')]) for d in data_year.Male]\n",
|
||||
"test_both = [float(d[:d.find(' ')]) for d in data_year.Both_sexes]\n",
|
||||
"test_female = [float(d[:d.find(' ')]) for d in data_year.Female]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 126,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame({'Year': data_year.Year, 'Both sexes': test_both, 'Male': test_male, 'Female': test_female})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 124,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame({'Year': [1], 'Both sexes': [2], 'Male': [3], 'Female': [4]})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 131,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>Age</th>\n",
|
||||
" <th>Both_sexes</th>\n",
|
||||
" <th>Male</th>\n",
|
||||
" <th>Female</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>85+</td>\n",
|
||||
" <td>23.97</td>\n",
|
||||
" <td>38.35</td>\n",
|
||||
" <td>16.87</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>75-84</td>\n",
|
||||
" <td>10.40</td>\n",
|
||||
" <td>15.22</td>\n",
|
||||
" <td>7.36</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>65-74</td>\n",
|
||||
" <td>6.82</td>\n",
|
||||
" <td>10.93</td>\n",
|
||||
" <td>3.57</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>55-64</td>\n",
|
||||
" <td>5.70</td>\n",
|
||||
" <td>9.50</td>\n",
|
||||
" <td>2.35</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>45-54</td>\n",
|
||||
" <td>5.25</td>\n",
|
||||
" <td>9.14</td>\n",
|
||||
" <td>1.73</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td>35-44</td>\n",
|
||||
" <td>5.42</td>\n",
|
||||
" <td>9.42</td>\n",
|
||||
" <td>1.50</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td>25-34</td>\n",
|
||||
" <td>4.89</td>\n",
|
||||
" <td>8.43</td>\n",
|
||||
" <td>1.36</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td>15-24</td>\n",
|
||||
" <td>4.00</td>\n",
|
||||
" <td>6.38</td>\n",
|
||||
" <td>1.34</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" Age Both_sexes Male Female\n",
|
||||
"0 85+ 23.97 38.35 16.87\n",
|
||||
"1 75-84 10.40 15.22 7.36\n",
|
||||
"2 65-74 6.82 10.93 3.57\n",
|
||||
"3 55-64 5.70 9.50 2.35\n",
|
||||
"4 45-54 5.25 9.14 1.73\n",
|
||||
"5 35-44 5.42 9.42 1.50\n",
|
||||
"6 25-34 4.89 8.43 1.36\n",
|
||||
"7 15-24 4.00 6.38 1.34"
|
||||
"Index(['', 'Male', 'Female'], dtype='object')"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"execution_count": 131,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"data_age"
|
||||
"pd.Index(['Both sexes' if 0 else '', 'Male', 'Female'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 133,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"a\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"if [0]:\n",
|
||||
" print('a')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 118,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"g = px.line(df, x='Year', y=df.columns[1:])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 119,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Figure({\n",
|
||||
" 'data': [],\n",
|
||||
" 'layout': {'legend': {'tracegroupgap': 0},\n",
|
||||
" 'margin': {'t': 60},\n",
|
||||
" 'template': '...',\n",
|
||||
" 'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'Year'}},\n",
|
||||
" 'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'value'}}}\n",
|
||||
"})\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(g)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"5.0"
|
||||
]
|
||||
},
|
||||
"execution_count": 88,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"10 / (2 if 1 else 10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user