tompollard / tableone

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

Melt casts integer values (0 and 1) to boolean (False and True) #76

Closed tompollard closed 5 years ago

tompollard commented 5 years ago

Starting with the following dataframe:

df = pd.DataFrame({'feature': [True,False,False,True], 
    'id': [1,0,1,2]})

and then counting the values using melt:

df.melt().groupby(['variable','value']).size().to_frame(name='freq')

Outputs:

001

This post suggests that the operation casts the values to object, and that pandas treats 0/1 as boolean for object conversion (which seems odd!).

As a result tableone currently displays False/True instead of 0/1 for the sample data:

t = TableOne(df, columns=['feature','id'], 
    categorical=['feature','id'])
screen shot 2018-11-21 at 11 17 25