[Python] Extract values from each row corresponding to a column and add it in a single row

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataframe with multiple rows that can be combined to a single row. I'm not sure how to do it.

    Input DataFrame:

    Emp#​
    Name​
    Week1​
    Week2​
    Week3​
    Week4
    1​
    mary​
    45​
    0​
    0​
    0
    1​
    mary​
    0​
    45​
    0​
    0
    1​
    mary​
    0​
    0​
    63​
    0
    1​
    mary​
    0​
    0​
    0​
    45
    2​
    john​
    0​
    0​
    0​
    0
    2​
    john​
    0​
    45​
    0​
    0
    2​
    john​
    0​
    0​
    0​
    0
    3​
    linda​
    0​
    0​
    63​
    0
    3​
    linda​
    45​
    0​
    0​
    0
    4​
    anup​
    0​
    45​
    0​
    0
    4​
    anup​
    45​
    0​
    0​
    0
    4​
    anup​
    0​
    0​
    0​
    45
    4​
    anup​
    0​
    0​
    63​
    0
    5​
    kumar​
    0​
    0​
    63​
    0
    5​
    kumar​
    45​
    0​
    0​
    0
    6​
    abc​
    0​
    45​
    0​
    0
    6​
    abc​
    0​
    0​
    0​
    45​

    Expected Dataframe:

    Emp#​
    Name​
    Week1​
    Week2​
    Week3​
    Week4
    1​
    mary​
    45​
    45​
    63​
    45
    2​
    john​
    0​
    45​
    64​
    45
    3​
    linda​
    45​
    63
    4​
    anup​
    45​
    45​
    63​
    45
    5​
    kumar​
    45​
    63
    6​
    abc​
    45​
    45​

    Tried groupby didnt work as expected. How to get this done?

    Continue reading...

Compartilhe esta Página