Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to calculate "n(%)" percentages over a row. Ref #108 #110

Merged
merged 2 commits into from
Jan 4, 2021

Conversation

tompollard
Copy link
Owner

Addresses #108 by adding a row_percent argument. If row_percent = True then the percentage for categorical variables will be calculated over the row (rather than column).

from tableone import TableOne, load_dataset
data = load_dataset('pn2012')

columns = ['Age', 'SysABP', 'Height', 'MechVent', 'ICU', 'death']

# columns containing categorical variables
categorical = ['ICU', 'MechVent']

# set decimal places for age to 0
decimals = {"Age": 0}

# non-normal variables
nonnormal = ['Age']

# optionally, a categorical variable for stratification
groupby = ['death']

t1 = TableOne(data, columns=columns,  categorical=categorical, groupby=groupby,
                        nonnormal=nonnormal, decimals=decimals, row_percent=True)

print(t1.tabulate(tablefmt = "github"))
Missing Overall 0 1
n 1000 864 136
Age, median [Q1,Q3] 0 68 [53,79] 66 [53,78] 75 [62,83]
SysABP, mean (SD) 291 114.3 (40.2) 115.4 (38.3) 107.6 (49.4)
Height, mean (SD) 475 170.1 (22.1) 170.3 (23.2) 168.5 (11.3)
MechVent, n (%) 0 0 540 (100.0) 468 (86.7) 72 (13.3)
1 460 (100.0) 396 (86.1) 64 (13.9)
ICU, n (%) CCU 0 162 (100.0) 137 (84.6) 25 (15.4)
CSRU 202 (100.0) 194 (96.0) 8 (4.0)
MICU 380 (100.0) 318 (83.7) 62 (16.3)
SICU 256 (100.0) 215 (84.0) 41 (16.0)

@tompollard tompollard merged commit 938fdf9 into master Jan 4, 2021
@tompollard tompollard deleted the row_percent branch January 4, 2021 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant