Automating dropping the columns with variance = 0

Viewed 35

I have a dataframe which has 377 columns, how do I automate (using a for loop probably) to check the nunique() of the columns and if it is equal to 1 which means the variance = 0, I want to drop that column. Please help me, highly grateful.

1 Answers

Try with nunqiue

out = df.loc[:,df.nunique()!=1]
Related