Note
Go to the end to download the full example code
Plotly - Sunburst (sari)
Warning
Please be patient, it might take some time to load.
9 # Plotly
10 import plotly.express as px
11
12 # Import own libraries
13 from pyamr.datasets.load import load_data_nhs
14
15
16 # --------------------------------------------------------------------
17 # Main
18 # --------------------------------------------------------------------
19 # Load data
20 data, antibiotics, organisms = load_data_nhs(nrows=1000)
21
22 # Create DataFrame
23 dataframe = data.groupby(['specimen_code',
24 'microorganism_code',
25 'antimicrobial_code',
26 'sensitivity']) \
27 .size().unstack().fillna(0)
28
29 # Compute frequency
30 dataframe['freq'] = dataframe.sum(axis=1)
31
32 # Compute sari
33 dataframe['sari'] = dataframe.resistant / \
34 (dataframe.resistant + dataframe.sensitive)
35
36 # Reset index
37 dataframe = dataframe.reset_index()
38
39 # -------------------------------------------
40 # Plot
41 # -------------------------------------------
42 # Show
43 fig = px.sunburst(dataframe,
44 path=['specimen_code',
45 'microorganism_code',
46 'antimicrobial_code'],
47 values='freq',
48 color='sari',
49 title='Sunburst of <Microorganisms, Antimicrobials> pairs')
50
51 # Show
52 #fig.show()
53 fig
Total running time of the script: ( 0 minutes 1.816 seconds)