title: Fastest way to know if a column has a constant value in a PySpark dataframe
body: <p>I want to assert if the values of a PySpark DataFrame column are the same across all rows. For example, having the next DataFrame</p>
  
  <pre><code>+----------+----------+
  |    A     |    B     |
  +----------+----------+
  |       2.0|       0.0|
  |       0.0|       0.0|
  |       1.0|       0.0|
  |       1.0|       0.0|
  |       0.0|       0.0|
  |       1.0|       0.0|
  |       0.0|       0.0|
  +----------+----------+
  </code></pre>
  
  <p>the column "A" is not constant and "B" is.</p>
  
  <p>I have tried two methods: </p>
  
  <p>1- Check the stddev = 0:</p>
  
  <pre><code>df.select(stddev(col('B'))).collect()
  </code></pre>
  
  <p>2- Get distinct values:</p>
  
  <pre><code>df.select("B").distinct().collect()
  </code></pre>
  
  <p>The first method takes 16min to finish and the second one 12min, but it's only one execution, so I'm not sure about significance.</p>
  
  <p>What is the best way to check it in PySpark?</p>