Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Samir Mena
Dynamic-Reports
Commits
d9ca9ead
Commit
d9ca9ead
authored
Nov 18, 2021
by
Samir Mena
👽
Browse files
First Commit
parent
9927d706
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
DynamicReports.py
0 → 100644
View file @
d9ca9ead
''' Start simple with Dash / Plotly '''
import
pandas
as
pd
import
plotly.express
as
px
import
dash
from
dash
import
dcc
from
dash
import
html
from
dash.dependencies
import
Output
,
Input
app
=
dash
.
Dash
(
__name__
)
#---------------------- auto run the broswer------------------------#
import
webbrowser
webbrowser
.
open_new
(
"http://127.0.0.1:8050"
)
#-----------------------------dataframe works ------------------------#
''' the data analysis task is to count the Down, No ,
Steady and Up for every mediceince and graph it'''
data_frame
=
pd
.
read_csv
(
'diabetes_data.csv'
)
data_frame
=
data_frame
.
loc
[:,
'metformin'
:
'metformin-pioglitazone'
]
df
=
pd
.
DataFrame
()
# empty data frame to collect "column in data_frame.columns"
for
column
in
data_frame
.
columns
:
# for each colum labeled with midicne do the following
df1
=
data_frame
[
column
].
value_counts
()
# count the occurance of (Down, No, Steady, Up) for each medicine
print
(
df1
)
# tst output
df
=
df
.
append
(
df1
)
# append / accomulator @ self
df
=
df
.
T
# transpose
df
.
index
.
rename
(
'Catagory'
,
inplace
=
True
)
#the indixing problem
df
.
reset_index
(
level
=
0
,
inplace
=
True
)
#the indixing problem
df
.
to_csv
(
'append.csv'
)
# tst output
#----------------------------graphs------------------------------#
#fig1 = px.bar(df, x='Down', y='metformin')
#fig_md = px.pie (df, names='Catagory', values='metformin')
#fig2 = px.bar(df, x='Catagory', y='metformin',barmode="group" , color='Catagory')
#fig = px.scatter(df, x="month", y="sales",size="sales", color="month", log_x=True, size_max=60)
#fig3 = px.pie (df, names='month', values='sales')
#fig4 = px.pie (df, names='month', values='cost')
#------------------------------app layout-------------------------#
app
.
layout
=
html
.
Div
([
html
.
H1
(
'Diabetes Medicine Abstraction '
),
dcc
.
Dropdown
(
id
=
'medicine'
,
options
=
[{
'label'
:
medc
,
'value'
:
medc
}
for
medc
in
data_frame
.
columns
],
value
=
'metformin'
),
dcc
.
Graph
(
id
=
"fig_bi"
,
figure
=
{}),
# the bi graph in html page
dcc
.
Graph
(
id
=
"fig_bar"
,
figure
=
{}),
# the bar graph
])
@
app
.
callback
(
# the link between def lst_update(value_in) > app.layout
Output
(
component_id
=
"fig_bi"
,
component_property
=
'figure'
),
#link to dcc.Graph(id="fig_bi" , figure={})
Output
(
component_id
=
"fig_bar"
,
component_property
=
'figure'
),
Input
(
component_id
=
'medicine'
,
component_property
=
'value'
)
)
def
lst_update
(
value_in
):
dff
=
df
[[
'Catagory'
,
value_in
]]
#dff.to_csv('dff.csv') # index see
#print(dff) tst dff
fig_md
=
px
.
pie
(
dff
,
names
=
'Catagory'
,
values
=
value_in
)
fig_bar
=
fig2
=
px
.
bar
(
dff
,
x
=
'Catagory'
,
y
=
value_in
,
barmode
=
"group"
)
return
fig_md
,
fig_bar
#----------------------------debug server------------------------#
if
__name__
==
"__main__"
:
app
.
run_server
(
debug
=
True
)
append.csv
0 → 100644
View file @
d9ca9ead
,Catagory,metformin,repaglinide,nateglinide,chlorpropamide,glimepiride,acetohexamide,glipizide,glyburide,tolbutamide,pioglitazone,rosiglitazone,acarbose,miglitol,troglitazone,tolazamide,examide,citoglipton,insulin,glyburide-metformin,glipizide-metformin,glimepiride-pioglitazone,metformin-rosiglitazone,metformin-pioglitazone
0,Down,575.0,45.0,11.0,1.0,194.0,,560.0,564.0,,118.0,87.0,3.0,5.0,,,,,12218.0,6.0,,,,
1,No,81778.0,100227.0,101063.0,101680.0,96575.0,101765.0,89080.0,91116.0,101743.0,94438.0,95401.0,101458.0,101728.0,101763.0,101727.0,101766.0,101766.0,47383.0,101060.0,101753.0,101765.0,101764.0,101765.0
2,Steady,18346.0,1384.0,668.0,79.0,4670.0,1.0,11356.0,9274.0,23.0,6976.0,6100.0,295.0,31.0,3.0,38.0,,,30849.0,692.0,13.0,1.0,2.0,1.0
3,Up,1067.0,110.0,24.0,6.0,327.0,,770.0,812.0,,234.0,178.0,10.0,2.0,,1.0,,,11316.0,8.0,,,,
diabetes_data.csv
0 → 100644
View file @
d9ca9ead
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment