tompollard / tableone

Create "Table 1" for research papers in Python
https://pypi.python.org/pypi/tableone/
MIT License
161 stars 38 forks source link

Optional Total/Overall column when groupby is used #50

Closed tompollard closed 4 years ago

tompollard commented 6 years ago

Consider adding an option to display an overall/total column when groupby is used (suggested by @theonesp). Miguel, you showed me an example of a paper that did this nicely. Please could you post a screenshot of the table here?

theonesp commented 6 years ago

Sure!, please find it below:

table_1

tompollard commented 6 years ago

table_1

theonesp commented 6 years ago

Reference: Subramaniam, B., Lerner, A., Novack, V., Khabbaz, K., Paryente-Wiesmann, M., Hess, P., & Talmor, D. (2014). Increased glycemic variability in patients with elevated preoperative HbA1C predicts adverse outcomes following coronary artery bypass grafting surgery. Anesthesia & Analgesia, 118(2), 277-287.

tompollard commented 4 years ago

@theonesp, sorry it took a bit of time to get to this! Version 0.7.1 now includes the overall column by default:

path = "https://raw.githubusercontent.com/tompollard/tableone/master/data/pn2012_demo.csv"

df = pd.read_csv(path)

cols = ["Age", "SysABP", "Height", "Weight", "ICU", "MechVent", "LOS", "death"]
categorical=["ICU", "MechVent", "death"]
strata = "MechVent"

t = TableOne(df, categorical=categorical, label_suffix=True, groupby=strata, 
    pval=True, smd=True, overall=True)
t

Screen Shot 2020-05-02 at 16 16 40