0

How could I drop a column where the row value is equal to 1?

Example: I want to keep the staff names where No. leaves taken is 0 and drop the rest of the columns

                     Jack    Mary    Huin   Lean
No. sales            340     200     100     122
No. leaves taken       1       0       3       0

Kusisi Karem
  • 107
  • 7

1 Answers1

1

Using .loc

df = df.loc[:, (df.filter(items=["No.leaves taken"], axis=0).eq(0)).any()]
print(df)

                 Mary  Lean
                           
No. sales         200   122
No.leaves taken     0     0
Jason Baker
  • 3,170
  • 2
  • 12
  • 15