title: Size of the sparse vector in the column of a data-frame in Apache scala spark
body: <p>I am using a vector assembler to transform a dataframe.</p>
  
  <pre><code>var stringAssembler = new VectorAssembler().setInputCols(encodedstringColumns).setOutputCol("stringFeatures")
  df = stringAssembler.transform(df)
  **var stringVectorSize = df.select("stringFeatures").head.size**
  var stringPca = new PCA().setInputCol("stringFeatures").setOutputCol("pcaStringFeatures").setK(stringVectorSize).fit(output)
  </code></pre>
  
  <p>Now stringVectorSize will tell PCA how many columns to keep while performing pca.
  I am trying to get the size of the output sparse vector from the vector assembler but my code gives size = 1 which is wrong. What is the right code to get the size of a sparse vector which is the part of a dataframe column.</p>
  
  <p>To put it plainly</p>
  
  <pre><code>+-------------+------------+-------------+------------+---+-----------+---------------+-----------------+--------------------+
  |PetalLengthCm|PetalWidthCm|SepalLengthCm|SepalWidthCm| Id|    Species|Species_Encoded|       Id_Encoded|      stringFeatures|
  +-------------+------------+-------------+------------+---+-----------+---------------+-----------------+--------------------+
  |          1.4|         0.2|          5.1|         3.5|  1|Iris-setosa|  (2,[0],[1.0])| (149,[91],[1.0])|(151,[91,149],[1....|
  |          1.4|         0.2|          4.9|         3.0|  2|Iris-setosa|  (2,[0],[1.0])|(149,[119],[1.0])|(151,[119,149],[1...|
  |          1.3|         0.2|          4.7|         3.2|  3|Iris-setosa|  (2,[0],[1.0])|(149,[140],[1.0])|(151,[140,149],[1...|
  </code></pre>
  
  <p>For the above dataframe . I want to extract the size of stringFeatures sparse vector ( which is 151)</p>