My dataframe is the following :
Files attr_1 attr_2 attr_3
file_1 X X X
file_2 X
file_3 X X
I want to transform it to :
Files attr
file_1 attr_1
file_1 attr_2
file_1 attr_3
file_2 attr_2
file_3 attr_1
file_3 attr_3
The closest I found was this question : Reconstruct a categorical variable from dummies in pandas
However for me to use the stack()
method I need to already have one line per file/attribute, ie the following :
Files attr_1 attr_2 attr_3
file_1 X
file_1 X
file_1 X
file_2 X
file_3 X
file_3 X
which is not my case unfortunately.
What is the cleanest way to achieve this ?