[Python] Reshape wide to long in pandas

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    Let's assume that I have the following dataframe in pandas:

    AA BB CC
    date
    05/03 1 2 3
    06/03 4 5 6
    07/03 7 8 9
    08/03 5 7 1


    and I want to transform it to the following:

    AA 05/03 1
    AA 06/03 4
    AA 07/03 7
    AA 08/03 5
    BB 05/03 2
    BB 06/03 5
    BB 07/03 8
    BB 08/03 7
    CC 05/03 3
    CC 06/03 6
    CC 07/03 9
    CC 08/03 1


    How can I do it?

    The reason of the transformation from wide to long is that, in the next stage, I would like to merge this dataframe with another one, based on dates and the initial column names (AA, BB, CC).

    Continue reading...

Compartilhe esta Página