如何在 Zeppelin/Spark/Scala 中漂亮地打印数据框?

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

我在 Zeppelin 0.7 笔记本中使用 Spark 2 和 Scala 2.11。我有一个可以像这样打印的数据框:

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

输出如下:

+---------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|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]                                                                     |

我正在努力使 Zeppelin 中的输出更好,方法是:

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

给出了这个输出:

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

和一个新的空白 Zeppelin 段落

[text: string, lemma: array]

有没有办法让数据框显示为格式良好的 table? TIA!

在 Zeppelin 中你可以使用 z.show(df) 来展示一个漂亮的 table。这是一个例子:

val df = Seq(
  (1,1,1), (2,2,2), (3,3,3)
).toDF("first_column", "second_column", "third_column")

z.show(df)

我知道这是一个旧线程,但以防万一它有帮助...

下面是我可以展示 df 的一部分的唯一方式。尝试按照评论中的建议向 .show() 添加第二个参数会引发错误。

z.show(df.limit(10))