Plotly - Timeseries

Todo

Explain and Simplify

'\n\n# --------------------------------------------------------------------\n#                               Main\n# --------------------------------------------------------------------\n# Load data\ndata, antibiotics, organisms = load_data_nhs()\n\n# Count records per specimen code\nspecimen_code_count = data     .groupby(\'laboratory_number\').head(1)     .specimen_code.value_counts(normalize=True)     .sort_values(ascending=False)\n\n# Filter most frequent specimens\ndata = data[data.specimen_code.isin(     specimen_code_count.index.values[:1])]\n\n# -------------------------------------------\n# Compute Freq and SARI\n# -------------------------------------------\n# Create instance\nfreq = Frequency(column_antibiotic=\'antimicrobial_code\',\n                 column_organism=\'microorganism_code\',\n                 column_date=\'date_received\',\n                 column_outcome=\'sensitivity\')\n\n# Create daily frequency\ndaily = freq.compute(data, strategy=\'ITI\',\n                      by_category=\'pairs\',\n                      fs=\'1M\')\n\ndaily[\'freq\'] = daily.sum(axis=1)\n\nimport plotly.express as px\nimport pandas as pd\n\nprint(daily)\n\ndaily = daily.reset_index()\ndaily = daily[daily.SPECIE.isin([\'ECOL\', \'PSEUD\']) &\n              daily.ANTIBIOTIC.isin([\'AAUG\'])]\n\n\n\nfig = px.bar(daily, x=\'DATE\', y=\'freq\',\n    title=\'Time Series with Range Slider and Selectors\',\n    facet_col=\'SPECIE\')\n\nfig.update_xaxes(\n    rangeslider_visible=True,\n    rangeselector=dict(\n        buttons=list([\n            dict(count=1, label="1m", step="month", stepmode="backward"),\n            dict(count=6, label="6m", step="month", stepmode="backward"),\n            dict(count=1, label="YTD", step="year", stepmode="todate"),\n            dict(count=1, label="1y", step="year", stepmode="backward"),\n            dict(step="all")\n        ])\n    )\n)\n\nfig.show()\n'

12 # Libraries
13 import sys
14 import glob
15 import numpy as np
16 import pandas as pd
17 import seaborn as sns
18 import matplotlib as mpl
19 import matplotlib.pyplot as plt
20
21 # Import own libraries
22 from pyamr.core.freq import Frequency
23 from pyamr.datasets.load import load_data_nhs
24
25 """
26
27 # --------------------------------------------------------------------
28 #                               Main
29 # --------------------------------------------------------------------
30 # Load data
31 data, antibiotics, organisms = load_data_nhs()
32
33 # Count records per specimen code
34 specimen_code_count = data \
35     .groupby('laboratory_number').head(1) \
36     .specimen_code.value_counts(normalize=True) \
37     .sort_values(ascending=False)
38
39 # Filter most frequent specimens
40 data = data[data.specimen_code.isin( \
41     specimen_code_count.index.values[:1])]
42
43 # -------------------------------------------
44 # Compute Freq and SARI
45 # -------------------------------------------
46 # Create instance
47 freq = Frequency(column_antibiotic='antimicrobial_code',
48                  column_organism='microorganism_code',
49                  column_date='date_received',
50                  column_outcome='sensitivity')
51
52 # Create daily frequency
53 daily = freq.compute(data, strategy='ITI',
54                       by_category='pairs',
55                       fs='1M')
56
57 daily['freq'] = daily.sum(axis=1)
58
59 import plotly.express as px
60 import pandas as pd
61
62 print(daily)
63
64 daily = daily.reset_index()
65 daily = daily[daily.SPECIE.isin(['ECOL', 'PSEUD']) &
66               daily.ANTIBIOTIC.isin(['AAUG'])]
67
68
69
70 fig = px.bar(daily, x='DATE', y='freq',
71     title='Time Series with Range Slider and Selectors',
72     facet_col='SPECIE')
73
74 fig.update_xaxes(
75     rangeslider_visible=True,
76     rangeselector=dict(
77         buttons=list([
78             dict(count=1, label="1m", step="month", stepmode="backward"),
79             dict(count=6, label="6m", step="month", stepmode="backward"),
80             dict(count=1, label="YTD", step="year", stepmode="todate"),
81             dict(count=1, label="1y", step="year", stepmode="backward"),
82             dict(step="all")
83         ])
84     )
85 )
86
87 fig.show()
88 """

Total running time of the script: ( 0 minutes 0.001 seconds)

Gallery generated by Sphinx-Gallery