[Python] Getting count of unqiue column values based on another column in df

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have df as below

    User Action
    =========================
    AA Page1
    AA Page1
    AA Page2
    BB Page2
    BB Page3
    CC Page3
    CC Page3


    Is there a way to get the count for different Pages for each user as a df. something like below

    User Page1 Page2 Page3
    ================================================
    AA 2 1 0
    BB 0 1 1
    CC 0 0 2


    So far i have tried to get the overall count all the actions per user

    df['User'].value_counts().reset_index(name='Action')


    What should i do to get the unique values of Action column as separate columns of a df and its count as values.

    Thanks

    Continue reading...

Compartilhe esta Página