tableone
tableone copied to clipboard
Binary Variables
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!
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!
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()))
Thanks @jpoles1, we'll take a look at implementing this!
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 :)
Thanks @jpoles1, we'll take a look at implementing this!
Awesome, thanks such much for the great work on this lib!
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.