[Python] How to generate this simple dataframe from these numbers?

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

  1. Stack

    Stack Membro Participativo

    I have N numbers, call it 3 for now: A1, A2, A3. I'd like to generate the following dataframe in python Pandas:

    Category 1 2 3 4 5 6 7 8
    1 A1 A1+A2 A1+A2+A3 A2+A3 A3 0 0 0
    2 0 A2 A2+A3 A2+A3+A1 A3+A1 A1 0 0
    3 0 0 A3 A3+A1 A3+A1+A2 A1+A2 A2 0

    I am completely at a loss as to how to generate the logic for this.

    My only thoughts are Take the 1st column, Add A2 to all values, Then add A3. Then add A1, although if it's already there then remove it. Seems thorny though.

    I'd like to run this for general N. Really appreciate the help. This is twisting my brain up.

    EDIT: Sorry about the table formatting. It keeps telling me it's code.

    Continue reading...

Compartilhe esta Página