Drop rows on multiple conditions in pandas dataframe

后端 未结 5 840
猫巷女王i
猫巷女王i 2020-12-05 11:37

My df has 3 columns

df = pd.DataFrame({\"col_1\": (0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0), 
                   \"col_2\": (0.0, 0.24, 1.0, 0.0, 0.22, 3.11, 0.0)         


        
5条回答
  •  余生分开走
    2020-12-05 12:16

    Try to filter your df with loc. It's so powerfull. The "~" means you want the opposit of your condition. The ":" means you want to keep all the columns

    df = df.loc[~((df['col_1'] == 1.0) & (df['col_2'] == 0.0)),:]
    

提交回复
热议问题