Melt multiple boolean columns in a single column in pandas
idxmax
df.idxmax(1).to_frame('OS')
OS
0 Windows
1 Linux
2 Mac
np.select
pd.DataFrame(
{'OS': np.select([*map(df.get, df)], [*df])},
df.index
)
OS
0 Windows
1 Linux
2 Mac
dot
df.dot(df.columns).to_frame('OS')
OS
0 Windows
1 Linux
2 Mac
np.where
Assuming only one True
per row
pd.DataFrame(
{'OS': df.columns[np.where(df)[1]]},
df.index
)
OS
0 Windows
1 Linux
2 Mac