[Python] Convert to True/False values of Pandas Dataframe

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a rather big dataframe that looks a bit like this:

    | obj1 | obj2 | obj3 |
    |------------------------
    0 | attr1 | attr2 | attr1 |
    1 | attr2 | attr3 | NaN |
    2 | attr3 | attrN | NaN |


    I'm new(ish) to pandas but I can't figure out a way to make it look like this:

    | obj1 | obj2 | obj3 |
    ------------------------
    attr1 | True | False | True |
    attr2 | True | False | False |
    attr3 | True | False | False |


    what's the most pythonic/fast way to go around this?

    EDIT

    I don't have any column in the dataframe with all the attributes. I could have an Obj4 that has an attribute which is not seen anywhere else

    Continue reading...

Compartilhe esta Página