[Python] Convert a column containing a single value to row in python pandas

Discussão em 'Python' iniciado por Stack, Abril 3, 2025.

  1. Stack

    Stack Membro Participativo

    Consider the following dataframe example:

    maturity_date simulation simulated_price realized_price
    30/06/2010 1 0.539333333 0.611
    30/06/2010 2 0.544 0.611
    30/06/2010 3 0.789666667 0.611
    30/06/2010 4 0.190333333 0.611
    30/06/2010 5 0.413666667 0.611


    Apart from setting aside the value of the last column and concatenating, is there any other way to adjust the dataframe such that the last column becomes row?

    Here is the desired output:

    maturity_date simulation simulated_price
    30/06/2010 1 0.539333333
    30/06/2010 2 0.544
    30/06/2010 3 0.789666667
    30/06/2010 4 0.190333333
    30/06/2010 5 0.413666667
    30/06/2010 realized_price 0.611

    Continue reading...

Compartilhe esta Página