I have a Dataframe which I am trying converting to html table syntax as a string in Scala:
sample_df: which is of type DataFrame = Dataset[Row]
|Name|Country|Occupation|Years_Experience|
|Bob |USA | Engineer | 5 |
|John|CANADA | Sales | 3 |
I already have the html headers converted however need to have the html rows and values in a string variable as below html_string:
<tr>
<td>Bob</td>
<td>USA</td>
<td>Engineer</td>
<td>5</td>
</tr>
<tr>
<td>John</td>
<td>CANADA</td>
<td>Sales</td>
<td>3</td>
</tr>
However when I try nested loop method below, the html_string variable is not being updated to what I am expecting above. It results in a blank. What am I doing wrong?
Code Attempt:
var html_string = """"""
for (i <- sample_df) {
html_string = html_string + "<tr>"
for (g <- i.toSeq) {
html_string = html_string + "<td>" + g + "</td>"
}
html_string = html_string + "</tr>"
}
println(html_string)
Thanks!
sample_df?