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

Support multilevel groupby #18

Open
tompollard opened this issue Feb 2, 2018 · 0 comments · May be fixed by #69
Open

Support multilevel groupby #18

tompollard opened this issue Feb 2, 2018 · 0 comments · May be fixed by #69

Comments

@tompollard
Copy link
Owner

tompollard commented Feb 2, 2018

It would be good to support multilevel groupby arguments. e.g. groupby = ['icu_type','gender'].

e.g.: achieve something similar to:

from tableone import TableOne
import pandas as pd

url="https://raw.githubusercontent.com/tompollard/tableone/master/data/pn2012_demo.csv"
data=pd.read_csv(url)

df = TableOne(data)

pd.concat([df.tableone,df.tableone], axis=1)

Notes:

# 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={'LOS': 'Length of stay', 'death': 'mortality'}

groupby = ['death']
second = 'ICU'
tdict = {}

for d in data[second].unique():
    print(d)
    tdict[d] =  TableOne(data[data[second] == d], columns, categorical, groupby, nonnormal)

pd.concat([tdict['SICU'].tableone,tdict['CSRU'].tableone,tdict['MICU'].tableone],axis=1)

pd.concat([tdict[x].tableone for x in data[second].unique()],axis=1)
@jtleider jtleider linked a pull request Aug 5, 2018 that will close this issue
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 a pull request may close this issue.

1 participant