Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Drop a column based on row values

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading