[Python] How do you remove a row in a pivot table in pandas?

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

  1. Stack

    Stack Membro Participativo

    I used this code to create a pivot in pandas:

    table = pd.pivot_table(df, values='Value (millions)', index=['TierA', 'TierB'], aggfunc=['count',np.sum])

    This gives me the pivot:

    count sum
    Value (millions) Value (millions)
    TierA TierB
    1 1 6 400
    2 0 0 0
    2 2 1 300


    In a pivot table how do I remove the [2,0,0,0] row? I tried the normal:

    table = table.drop(['TierA','TierB','count','sum'], axis =0)

    It didn't work, and neither did this: table = table.drop(['TierA','TierB','Value (millions)'], axis =0)

    Is what i'm trying to do possible? If so, how would I go about it?

    Thanks

    Continue reading...

Compartilhe esta Página