I have a DataFrame in Apache Spark SQL, where I want to drop all columns where all not None values are the same.
So in a dummy example
df
| A | B | C |
1 2 3
NaN 2 4
1 2 NaN
1 2 5
I want to keep only column C
df_filter
| C |
3
4
NaN
5
In Python I would do it in the following way
nunique = df.fillna(df.median()).nunique()
cols_to_drop = nunique[nunique == 1].index
df = df.drop(cols_to_drop, axis=1)
But how would I do it in Apache Spark SQL DataFrame (Scala)?