title: Scala: How to return column name and value from a dataframe
body: <p>I am trying to create a function which can scan a dataframe row by row and, for each row, spit out the non empty columns and the column names. But the challenge is that I dont know the number of columns or their names in the input dataframe. </p>
  
  <p>A function something like <code>GetNotEmptyCols(InputRow: Row): (Colname:String, ColValue:String)</code></p>
  
  <p>As sample data, consider the following dataframes. </p>
  
  <pre><code>val DataFrameA = Seq(("tot","","ink"), ("yes","yes",""), ("","","many")).toDF("ColA","ColB","ColC")
  val DataFrameB = Seq(("yes",""), ("","")).toDF("ColD","ColE")
  </code></pre>
  
  <p>I have been trying to get the column value for each row object but dont know how to do that when I dont have the names of columns. I could extract the column names from the dataframe and pass it to the function as an additional variable but am hoping for a better approach since row object should have the column names and I should be able to extract them.</p>
  
  <p>The output I am working to get is something like this:</p>
  
  <pre><code>DataFrameA.foreach{ row =&gt; GetNotEmptyCols(row)} gives output 
  
  For row1: ("ColA", "tot"), ("ColC", "ink")
  For row2: ("ColA","yes"),("ColB","yes")
  For row3: ("ColC","many")
  
  DataFrameB.foreach{ row =&gt; GetNotEmptyCols(row)} gives output
  For row1: ("ColD", "yes")
  For row2: ()
  </code></pre>