[Python] Removing rows from pandas if they match multiple column of other row of same dataframe

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

  1. Stack

    Stack Membro Participativo

    I am trying to remove all the rows in which value of Total, first and second is equal to the row which is marked by label M within a netting

    DataFrame (pandas)

    netting Total first second lable
    01 9358.66 358.69 9717.35 M
    01 9358.66 358.69 717.35 X
    01 9358.66 358.69 9717.35 X
    01 9358.66 358.69 9717.35 X
    01 9358.66 358.69 9717.35 X
    02 100 100 100 M
    02 100 100 100 Y


    Expected output is

    netting Total first second lable
    01 9358.66 358.69 9717.35 M
    01 9358.66 358.69 717.35 X
    01 9358.66 358.69 9717.35 X --> dropped
    01 9358.66 358.69 9717.35 X --> dropped
    01 9358.66 358.69 9717.35 X --> dropped
    02 100 100 100 M
    02 100 100 100 Y --> dropped


    Final Data frame will look like this.

    netting Total first second lable
    01 9358.66 358.69 9717.35 M
    01 9358.66 358.69 717.35 X
    02 100 100 100 M


    I am just starting out in Pandas, any help will be appreciated, thanks !!!

    Continue reading...

Compartilhe esta Página