Package: tableone
tableonetableone 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 citationIf 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/ooy012DocumentationFor documentation, see:http://tableone.readthedocs.io/en/latest/. An executable demonstration of the package is availableon GitHubas a Jupyter Notebook. The easiest way to try out this notebook is toopen 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 oftableoneWhile 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 oftableonealongside 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 usingtableonefor a research study, especially prior to submitting the study for publication.OverviewAt a high level, you can use the package as follows:Import the data into a pandas DataFrameRun tableone on this dataframe to output summary statisticsSpecify 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 variablesLimit 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).InstallationTo install the package with pip, run:pip install tableoneTo install this package with conda, run:conda install -c conda-forge tableoneExample usageImport libraries:fromtableoneimportTableOne,load_datasetimportpandasaspdLoad 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 categorical variable for stratification, a list of non-normal variables, and a dictionary of alternative labels:groupby=['death']nonnormal=['Age']labels={'death':'mortality'}Create an instance of TableOne with the input arguments:mytable=TableOne(data,columns=columns,categorical=categorical,groupby=groupby,nonnormal=nonnormal,rename=labels,pval=False)Display the table using thetabulatemethod. Thetablefmtargument 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:Missing01n864136Age066 [52,78]75 [62,83]SysABP291115.36 (38.34)107.57 (49.43)Height475170.33 (23.22)168.51 (11.31)Weight30283.04 (23.58)82.29 (25.40)ICUCCU0137 (15.86)25 (18.38)CSRU194 (22.45)8 (5.88)MICU318 (36.81)62 (45.59)SICU215 (24.88)41 (30.15)mortality00864 (100.0)1136 (100.0)Tables can be exported to file in various formats, including LaTeX, CSV, and HTML. Files are exported by calling theto_formatmethod 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')