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

How to drop the columns in pandas with multiple condtions

I am new to python and pandas

On the below data frame ,I need to the drop the columns which are totally "None" , with "blanks and None", but not the columns with values and None

data frame

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

On the above table, I want Column A and C to be dropped because they are totally "None" or "blank and None", but Column B has some valid data at least in 3 cells, it should not be disturbed

how to give this condition in df.drop (pandas)

>Solution :

Use:

m = df.isna() | df.isin(['', 'None', 'none'])

df = df.loc[:, ~m.all()]

Or like comment, only in output are replaced values:

df = df.replace(['', 'None', 'none'],np.nan).dropna(axis=1, how='all')
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