tompollard / tableone

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

Allow labelling of 'isnull' column #86

Closed cx1111 closed 4 years ago

cx1111 commented 4 years ago

Hi authors, thanks for the nice package.

It would be nice if there were a way to display the calculated 'isnull' column under another label.

tompollard commented 4 years ago

Version 0.6.2 (on pip now, and conda shortly) allows you to rename the isnull and overall columns.

In the new version, the labels argument has been changed to rename. You can include isnull in the dictionary of variables to rename.

e.g.:

# load sample data into a pandas dataframe
url="https://raw.githubusercontent.com/tompollard/tableone/master/data/pn2012_demo.csv"
data=pd.read_csv(url)

# columns to be summarized
columns = ['Age', 'SysABP', 'Height', 'Weight', 'ICU', 'death']

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

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

# alternative labels
labels={'isnull': 'missing'}

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

# create tableone with the input arguments
mytable = TableOne(data, columns=columns, categorical=categorical, 
    nonnormal=nonnormal, rename=labels, label_suffix=True, decimals=decimals)

mytable