Filtering pandas dataframe with multiple Boolean columns

前端 未结 5 2028
闹比i
闹比i 2020-12-05 07:26

I am trying to filter a df using several Boolean variables that are a part of the df, but have been unable to do so.

Sample data:

A | B | C | D
John         


        
5条回答
  •  醉话见心
    2020-12-05 08:24

    you could try this easily:

    df1 = df[(df['C']=='True') | (df['D']=='True')]
    

    Note:

    1. The or logical operator needs to be replaced by the bitwise | operator.
    2. Ensure that () are used to enclose each of the operands.

提交回复
热议问题