[Python] Transform Dataframe with Duplicate Date Entries

Discussão em 'Python' iniciado por Stack, Junho 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataframe that looks like this (so there is no unique Index):

    Date Data Product
    1/1/25 1 A
    2/1/25 2 A
    3/1/25 3 A
    1/1/25 1 B
    2/1/25 4 B
    3/1/25 5 B
    1/1/25 1 C
    2/1/25 6 C
    3/1/25 7 C

    There are many products in this dataframe (not just 3). I want to transform it so each product has its own column for the 'Data' column like this (with the name based on the Product column).

    Date Data_A Data_B Data_C
    1/1/25 1 1 1
    2/1/25 2 4 6
    3/1/25 3 5 7

    I thought maybe I could select only the rows for each Product and then merge each Product to a new dataframe? Would love to know the easiest way to do this. Thank you!

    Continue reading...

Compartilhe esta Página