.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples\tableone\plot_main02.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_tableone_plot_main02.py: 02. Summary statistic for Dengue data ========================================================= This script demonstrates a fundamental application of the tableone Python library for creating a clinical summary table. Using a dengue patient dataset, it showcases the process of summarizing patient characteristics. The script loads the data, selects key demographic and clinical variables (like age, gender, and platelet count), and defines a grouping variable to compare these characteristics across different patient subgroups. Finally, it generates and displays the formatted summary table. .. GENERATED FROM PYTHON SOURCE LINES 14-47 .. code-block:: default :lineno-start: 14 # Libraries import pandas as pd # Specific from pathlib import Path from tableone import TableOne # ------------------------ # Load data # ------------------------ # Load data path = Path('../../datasets/dengue-htd-dataset') data = pd.read_csv(path / 'dengue.csv') print(data) print(data.columns) # ------------------------ # Create tableone # ------------------------ # Columns columns = ['age', 'gender', 'haematocrit_percent', 'plt'] # Categorical categorical = ['gender'] # Groupby groupby = 'cvs_hos_split' # mytable = TableOne(data, columns=columns, categorical=categorical, groupby=groupby) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Unnamed: 0 index age gender haematocrit_percent plt outcome missing ... split_2 split_3 split_4 split_5 split_6 split_7 split_8 split_9 0 0 0 84.0 1 42.0 20.0 0 0 ... train train train train train train train train 1 1 1 84.0 1 36.0 107.0 0 0 ... NaN NaN NaN NaN NaN NaN NaN NaN 2 2 2 39.0 1 32.0 145.0 0 0 ... train train train train train train train train 3 3 3 39.0 1 35.5 120.0 0 0 ... NaN NaN NaN NaN NaN NaN NaN NaN 4 4 4 39.0 1 29.0 93.0 0 0 ... NaN NaN NaN NaN NaN NaN NaN NaN .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 520 520 520 30.0 1 35.7 61.0 0 0 ... train train train train train train train test 521 521 521 30.0 1 38.5 93.0 0 0 ... NaN NaN NaN NaN NaN NaN NaN NaN 522 522 522 30.0 1 42.1 61.0 0 0 ... train train train train train train train test 523 523 523 30.0 1 39.3 63.0 0 0 ... train train train train train train train test 524 524 524 30.0 1 37.8 78.0 0 0 ... train train train train train train train test [525 rows x 19 columns] Index(['Unnamed: 0', 'index', 'age', 'gender', 'haematocrit_percent', 'plt', 'outcome', 'missing', 'cvs_hos_split', 'split_0', 'split_1', 'split_2', 'split_3', 'split_4', 'split_5', 'split_6', 'split_7', 'split_8', 'split_9'], dtype='object') .. GENERATED FROM PYTHON SOURCE LINES 48-50 Lets see the table .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: default :lineno-start: 51 mytable.tableone .. raw:: html
Grouped by cvs_hos_split
Missing Overall cvs hos
n 525 393 132
age, mean (SD) 0 37.3 (16.3) 37.4 (16.3) 36.9 (16.5)
gender, n (%) 0 249 (47.4) 190 (48.3) 59 (44.7)
1 276 (52.6) 203 (51.7) 73 (55.3)
haematocrit_percent, mean (SD) 0 38.5 (8.6) 38.2 (8.6) 39.3 (8.7)
plt, mean (SD) 0 106.5 (132.5) 110.8 (146.6) 93.8 (75.9)


.. GENERATED FROM PYTHON SOURCE LINES 54-57 Lets show the raw HTML Html .. GENERATED FROM PYTHON SOURCE LINES 57-61 .. code-block:: default :lineno-start: 57 html = mytable.to_html() # show print(html) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none
Grouped by cvs_hos_split
Missing Overall cvs hos
n 525 393 132
age, mean (SD) 0 37.3 (16.3) 37.4 (16.3) 36.9 (16.5)
gender, n (%) 0 249 (47.4) 190 (48.3) 59 (44.7)
1 276 (52.6) 203 (51.7) 73 (55.3)
haematocrit_percent, mean (SD) 0 38.5 (8.6) 38.2 (8.6) 39.3 (8.7)
plt, mean (SD) 0 106.5 (132.5) 110.8 (146.6) 93.8 (75.9)
.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.135 seconds) .. _sphx_glr_download__examples_tableone_plot_main02.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_main02.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_main02.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_