How can I pretty print a data frame in Zeppelin/Spark/Scala?

Viewed 32573

I am using Spark 2 and Scala 2.11 in a Zeppelin 0.7 notebook. I have a dataframe that I can print like this:

dfLemma.select("text", "lemma").show(20,false)

and the output looks like:

+---------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|text                                                                                                                       |lemma                                                                                                                                                                  |
+---------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|RT @Dope_Promo: When you and your crew beat your high scores on FUGLY FROG  https://time.com/Sxp3Onz1w8                    |[rt, @dope_promo, :, when, you, and, you, crew, beat, you, high, score, on, FUGLY, FROG, https://time.com/sxp3onz1w8]                                                      |
|RT @axolROSE: Did yall just call Kermit the frog a lizard?  https://time.com/wDAEAEr1Ay                                        |[rt, @axolrose, :, do, yall, just, call, Kermit, the, frog, a, lizard, ?, https://time.com/wdaeaer1ay]                                                                     |

I am trying to make the output nicer in Zeppelin, by:

val printcols= dfLemma.select("text", "lemma")
println("%table " + printcols)

which gives this output:

printcols: org.apache.spark.sql.DataFrame = [text: string, lemma: array<string>]

and a new blank Zeppelin paragraph headed

[text: string, lemma: array]

Is there a way of getting the dataframe to show as a nicely formatted table? TIA!

2 Answers

I know this is an old thread, but just in case it helps...

The below was the only way that I could take show a portion of the df. Trying to add a second parameter to .show() as suggested in the comments is throwing an error.

z.show(df.limit(10))

Related