generated from nhsx/open-analytics-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
73 lines (49 loc) · 2.72 KB
/
main.py
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
72
73
import plotly.express as px
from plotly import graph_objects as go
import pandas as pd
#import chart_studio.tools as tls
df_gp = pd.read_csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/data/gp-reg-pat-prac-map.csv')
list_of_ccgs = df_gp['CCG_CODE'].unique()
num_of_ccgs = len(list_of_ccgs)
list_of_pcns = df_gp['PCN_NAME'].unique()
num_of_pcns = len(list_of_pcns)
list_of_stps = df_gp['STP_NAME'].unique()
num_of_stps = len(list_of_stps)
df_gp_cut = df_gp[['PRACTICE_NAME', 'PCN_NAME', 'CCG_NAME', 'STP_NAME', 'COMM_REGION_NAME']]
#load in data and retrieve the number of trusts
df_trusts = pd.read_csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/data/etr.csv', header = None)
list_of_trusts = df_trusts[1].unique()
num_of_trusts = len(list_of_trusts)
#merge df_gp with df_trusts
df_trusts_cut = df_trusts.iloc[:, 0:3]
#df_trusts_cut.columns = ["Trust_Code", "Trust_Name", "Trust_ONS_Code"]
"""
#create dict and display funnel chart
data_funnel = dict(number = [7, num_of_stps, num_of_ccgs, num_of_trusts, num_of_pcns, 6528], stage = ["Regions", "ICS", "CCG", "Trusts", "PCN", "GP Practices"])
fig = px.funnel(data_funnel, x= 'number', y = 'stage')
#fig.show()
#create a sunburst chart mapping regions-stps-ccgs-pcn-practices
print(df_gp_cut)
fig2 = px.sunburst(df_gp_cut, path = ['COMM_REGION_NAME', 'STP_NAME', 'CCG_NAME', 'PCN_NAME', 'PRACTICE_NAME'], values = None)
#fig2.show()
#create a mediuym sunburst chart mapping regions-stps-ccgs-trusts
fig3 = px.sunburst(df_gp_cut, path = ['COMM_REGION_NAME', 'STP_NAME', 'CCG_NAME', 'TRUST_NAME'], values = None)
fig3.show()
#create a smaller sunburst chart mapping regions-stps-ccgs
fig4 = px.sunburst(df_gp_cut, path = ['COMM_REGION_NAME', 'STP_NAME', 'CCG_NAME'], values = None)
#fig4.show()
#create a treemap mapping regions-stps-ccgs-pcns-practices
fig5= px.treemap(df_gp_cut, path = ['COMM_REGION_NAME', 'STP_NAME', 'CCG_NAME', 'PCN_NAME', 'PRACTICE_NAME'], values = None)
#fig5.show()
#create a smaller treemap mapping regions-stps-ccgs
fig6 = px.treemap(df_gp_cut, path = ['COMM_REGION_NAME', 'STP_NAME', 'CCG_NAME'], values = None)
#fig6.show()
#saving all plotly figures
'''
fig.write_html("/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/map outputs/funnel_chart.html")
fig2.write_html("/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/map outputs/sunburst_large.html")
fig3.write_html("/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/map outputs/sunburst_small.html")
fig4.write_html("/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/map outputs/treemap_large.html")
fig5.write_html("/Users/muhammad-faaiz.shanawas/Documents/GitHub/SystemHierarchies/map outputs/treemap_small.html")
'''
"""