Deleting columns from a csv if it contains a certain value

I have a csv from which I want to drop the columns which has only ‘-‘ values in it. These are the columns I want to drop:

enter image description here

How can I do this?

Answer

Use DataFrame.ne for test not - value with DataFrame.all for test if not exist in all rows anf filter by DataFrame.loc – first : means al rows and second is mask for filter columns:

df = df.loc[:, df.ne('-').all()]

Leave a Reply

Your email address will not be published. Required fields are marked *