tableone icon indicating copy to clipboard operation
tableone copied to clipboard

Binary Variables

Open jpoles1 opened this issue 3 years ago • 5 comments

It would be nice if there was a way to display binary variables, other than making them categorical, in which case both True and False are shown. The ideal would be to have just the values for the "True" category displayed, I think it would look far more professional!

image

jpoles1 avatar Jan 14 '21 21:01 jpoles1

I tried looking into the TableOne code a bit, and it's looking like a PR is something I don't have quite enough time for right now, unfortunately. For anyone looking for a quick and dirty solution, you can do the following:

table1 = TableOne()
table1 = table1.tableone #access underlying pandas df
table1 = table1[table1.index.get_level_values(1) != "False"] #Remove rows with "False"
table1.rename(index={"True": ""}, inplace=True) #Rename "True" to blank

and now it works perfectly!

image

PS: If you want to make your reformatted tables look pretty, you can use some css styles as below:

table1 = table1.style.set_table_styles(table_styles)
display(HTML(table1.render()))

jpoles1 avatar Jan 14 '21 22:01 jpoles1

Thanks @jpoles1, we'll take a look at implementing this!

tompollard avatar Jan 15 '21 00:01 tompollard

You wouldn't believe that I started to post this exact feature request a few days ago and then decided not to post it :)

I did solve it using pandas as suggested. But I would appreciate if this feature is added :)

raheems avatar Jan 15 '21 01:01 raheems

Thanks @jpoles1, we'll take a look at implementing this!

Awesome, thanks such much for the great work on this lib!

jpoles1 avatar Jan 15 '21 05:01 jpoles1

Is there a way to include p values when only displaying the True binary variables? When I used the "quick and dirty" method to only include the binary variables listed as True, the calculated p values were removed from the table.

dnatanov avatar Jul 12 '21 20:07 dnatanov