title: clean missing values spark with aggregation function
body: <p>I would like to clean missing values by replacing them by the mean.This source code used to work i do not why , it doesn't work now.Any help will be appreciated.
  Here is the dataset i use </p>
  
  <pre><code>RowNumber,Poids,Age,Taille,0MI,Hmean,CoocParam,LdpParam,Test2,Classe
  0,,72,160,5,,2.9421,,3,4
  1,54,70,,5,0.6301,2.7273,,3,
  2,,51,164,5,,2.9834,,3,4
  3,,74,170,5,0.6966,2.9654,2.3699,3,4
  4,108,62,,5,0.6087,2.7093,2.1619,3,4
  </code></pre>
  
  <p>Here what i did </p>
  
  <pre><code> val spark = SparkSession.builder.master("local").appName("my-spark-app").getOrCreate()
  
      val df = spark.read.option("header", true).option("inferSchema", true).format("com.databricks.spark.csv").load("C:/Users/mhattabi/Desktop/data_with_missing_values3.csv")
      df.show(false)
      var newDF = df
      df.dtypes.foreach { x =&gt;
        val colName = x._1
        newDF = newDF.na.fill(df.agg(max(colName)).first()(0).toString, Seq(colName))
      }
      newDF.show(false)
  </code></pre>
  
  <p>Here is the result , nothing happened </p>
  
  <pre><code>initial_data
  
      +---------+-----+---+------+---+------+---------+--------+-----+------+
      |RowNumber|Poids|Age|Taille|0MI|Hmean |CoocParam|LdpParam|Test2|Classe|
      +---------+-----+---+------+---+------+---------+--------+-----+------+
      |0        |null |72 |160   |5  |null  |2.9421   |null    |3    |4     |
      |1        |54   |70 |null  |5  |0.6301|2.7273   |null    |3    |null  |
      |2        |null |51 |164   |5  |null  |2.9834   |null    |3    |4     |
      |3        |null |74 |170   |5  |0.6966|2.9654   |2.3699  |3    |4     |
      |4        |108  |62 |null  |5  |0.6087|2.7093   |2.1619  |3    |4     |
      +---------+-----+---+------+---+------+---------+--------+-----+------+
  
      new_data
      +---------+-----+---+------+---+------+---------+--------+-----+------+
      |RowNumber|Poids|Age|Taille|0MI|Hmean |CoocParam|LdpParam|Test2|Classe|
      +---------+-----+---+------+---+------+---------+--------+-----+------+
      |0        |null |72 |160   |5  |null  |2.9421   |null    |3    |4     |
      |1        |54   |70 |null  |5  |0.6301|2.7273   |null    |3    |null  |
      |2        |null |51 |164   |5  |null  |2.9834   |null    |3    |4     |
      |3        |null |74 |170   |5  |0.6966|2.9654   |2.3699  |3    |4     |
      |4        |108  |62 |null  |5  |0.6087|2.7093   |2.1619  |3    |4     |
      +---------+-----+---+------+---+------+---------+--------+-----+------+
  </code></pre>
  
  <p>What should i do </p>