I have an issue in reshaping a pandas DatFrame. It looks like this (the numbers of lines and columns can vary) :
columns col1 col2 col3 col4
Species
sp1 218.000000 521.000000 533.000000 793.000000
sp1 0.105569 0.252300 0.258111 0.384019
sp1 2 2 2 3
sp2 225.000000 521.000000 540.000000 800.000000
sp2 0.107862 0.249760 0.258869 0.383509
sp2 2 2 2 3
sp3 217.000000 477.000000 512.000000 725.000000
sp3 0.112377 0.247022 0.265148 0.375453
sp3 1 1 3 3
The column Species
is my index. I want to reshape it like this :
Species columns c f p
sp1 col1 218.000000 0.105569 2
sp1 col2 521.000000 0.252300 2
sp1 col3 533.000000 0.258111 2
sp1 col4 793.000000 0.384019 3
sp2
sp2
sp2
sp2
sp3 etc
sp3
sp3
sp3
But I can't find how to do.
The purpose is to then make a heatmap with the p.rect()
function of bokeh, the x-axis being the columns c
or f
, the y-axis being the column Species
. The size of the rectangle would be determined by the column p
.
Thanks in advance.