How to drop columns which have same values in all rows via pandas or spark dataframe?
Suppose I've data similar to following: index id name value value2 value3 data1 val5 0 345 name1 1 99 23 3 66 1 12 name2 1 99 23 2 66 5 2 name6 1 99 23 7 66 How can we drop all those columns like ( value , value2 , value3 ) where all rows have same values, in one command or couple of commands using python ? Consider we have many columns similar to value , value2 , value3 ... value200 . Output: index id name data1 0 345 name1 3 1 12 name2 2 5 2 name6 7 EdChum What we can do is apply nunique to calc the number of unique values in the df and drop the columns which only have a single unique value: