I want to write a script that returns the constant columns from a predefined dataframe. I got the idea of comparing each column min and max value, if they are equal I will append the column to a constant column list. This is how I'am doing it:
let's suppose I Have this dataframe:
>> df = spark.createDataFrame([(1., 4.,7.), (2., 5.,7.), (3., 6.,7.)], ["A", "B", "C"])
>> df.show()
+---+---+---+
| A| B| C|
+---+---+---+
|1.0|4.0|7.0|
|2.0|5.0|7.0|
|3.0|6.0|7.0|
+---+---+---+
So here I have the "C" colum is constant as it contains the same value "7.0".
>> minA = df.agg({"A": "min"})
>> maxA = df.agg({"A": "max"})
>> minC = df.agg({"C": "min"})
>> maxC = df.agg({"C": "max"})
The next step is to compare in each case the min and max value:
>>> maxA["max(A)"] == minA["min(A)"]
Column<(max(A) = min(A))>
>>> maxC["max(C)"] == minC["min(C)"]
Column<(max(C) = min(C))>
those results are meaningless, how do I solve this issue knowing that I dont want to use .collect() to retreive min and max value because this script has to work also in enormous amount of data and collect is not a good plan to go for it!