tableone is a package for creating 'Table 1' summary statistics for a patient population.
Project description
tableone
tableone is a package for creating "Table 1" summary statistics for a patient population. It was inspired by the R package of the same name by Yoshida and Bohn.
Suggested citation
If you use tableone in your study, please cite the following paper:
Tom J Pollard, Alistair E W Johnson, Jesse D Raffa, Roger G Mark; tableone: An open source Python package for producing summary statistics for research papers, JAMIA Open, https://doi.org/10.1093/jamiaopen/ooy012
Documentation
For documentation, see: http://tableone.readthedocs.io/en/latest/. An executable demonstration of the package is available on GitHub as a Jupyter Notebook. The easiest way to try out this notebook is to open it in Google Colaboratory. A paper describing our motivations for creating the package is available at: https://doi.org/10.1093/jamiaopen/ooy012.
A note for users of tableone
While we have tried to use best practices in creating this package, automation of even basic statistical tasks can be unsound if done without supervision. We encourage use of tableone
alongside other methods of descriptive statistics and, in particular, visualization to ensure appropriate data handling.
It is beyond the scope of our documentation to provide detailed guidance on summary statistics, but as a primer we provide some considerations for choosing parameters when creating a summary table at: http://tableone.readthedocs.io/en/latest/bestpractice.html.
Guidance should be sought from a statistician when using tableone
for a research study, especially prior to submitting the study for publication.
Overview
At a high level, you can use the package as follows:
- Import the data into a pandas DataFrame
- Run tableone on this dataframe to output summary statistics
- Specify your desired output format: text, latex, markdown, etc.
Additional options include:
- Select a subset of columns.
- Specify the data type (e.g.
categorical
,numerical
,nonnormal
). - Compute p-values, and adjust for multiple testing (e.g. with the Bonferroni correction).
- Compute standardized mean differences (SMDs).
- Provide a list of alternative labels for variables
- Limit the output of categorical variables to the top N rows.
- Display remarks relating to the appopriateness of summary measures (for example, computing tests for multimodality and normality).
Installation
To install the package with pip, run:
pip install tableone
To install this package with conda, run:
conda install -c conda-forge tableone
Example usage
- Import libraries:
from tableone import TableOne, load_dataset
import pandas as pd
- Load sample data into a pandas dataframe:
data=load_dataset('pn2012')
- Optionally, a list of columns to be included in Table 1:
columns = ['Age', 'SysABP', 'Height', 'Weight', 'ICU', 'death']
- Optionally, a list of columns containing categorical variables:
categorical = ['ICU', 'death']
- Optionally, a list of columns containing continuous variables:
continuous = ['Age', 'SysABP', 'Height', 'Weight']
- Optionally, a categorical variable for stratification, a list of non-normal variables, and a dictionary of alternative labels:
groupby = 'death'
nonnormal = ['Age']
rename={'death': 'mortality'}
- Create an instance of TableOne with the input arguments:
mytable = TableOne(data, columns=columns, categorical=categorical, continuous=continuous, groupby=groupby, nonnormal=nonnormal, rename=rename, pval=False)
- Display the table using the
tabulate
method. Thetablefmt
argument allows the table to be displayed in multiple formats, including "github", "grid", "fancy_grid", "rst", "html", and "latex".
print(mytable.tabulate(tablefmt = "fancy_grid"))
- ...which prints the following table to screen:
Grouped by mortality:
Missing | 0 | 1 | ||
---|---|---|---|---|
n | 864 | 136 | ||
Age | 0 | 66 [52,78] | 75 [62,83] | |
SysABP | 291 | 115.36 (38.34) | 107.57 (49.43) | |
Height | 475 | 170.33 (23.22) | 168.51 (11.31) | |
Weight | 302 | 83.04 (23.58) | 82.29 (25.40) | |
ICU | CCU | 0 | 137 (15.86) | 25 (18.38) |
CSRU | 194 (22.45) | 8 (5.88) | ||
MICU | 318 (36.81) | 62 (45.59) | ||
SICU | 215 (24.88) | 41 (30.15) | ||
mortality | 0 | 0 | 864 (100.0) | |
1 | 136 (100.0) |
- Tables can be exported to file in various formats, including LaTeX, CSV, and HTML. Files are exported by calling the
to_format
method on the tableone object. For example, mytable can be exported to an Excel spreadsheet named 'mytable.xlsx' with the following command:
mytable.to_excel('mytable.xlsx')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tableone-0.9.1.tar.gz
.
File metadata
- Download URL: tableone-0.9.1.tar.gz
- Upload date:
- Size: 770.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96c4b5b5820a204488e26c1ed88bbe8bec89ce5d128c11c3adab94bd26ac58e4 |
|
MD5 | 9612d85cad78cff45c1d957c59a29230 |
|
BLAKE2b-256 | ff0498b6c6a15940878649a086e1bd3009a2171164cec77249778ff6612b4bbc |
File details
Details for the file tableone-0.9.1-py3-none-any.whl
.
File metadata
- Download URL: tableone-0.9.1-py3-none-any.whl
- Upload date:
- Size: 41.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b20994b0a63286ba1511d7ff691f42d6112e6ecbb773e020327d14dcdc9d44b7 |
|
MD5 | 270c73c9d0a29f0c82666c6715bdf43c |
|
BLAKE2b-256 | b2019c40c5b80fef59e96f96c520767d9e6ddd5c46411ef2cff073782c79a1a5 |