2017-07-06 83 views
6

我在Zeppelin 0.7筆記本中使用Spark 2和Scala 2.11。我有一個數據幀,我可以打印這樣的:我如何在Zeppelin/Spark/Scala中打印數據框?

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

我試圖在齊柏林輸出更好,通過:

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

它給出了這個輸出:

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

和一個新的空白齊柏林款爲首

[text: string, lemma: array] 

有沒有得到數據幀顯示爲一個很好的格式化表格的方式嗎? TIA! TIA!

回答

16

在Zeppelin中,您可以使用z.show(df)來顯示一張漂亮的桌子。這裏有一個例子:

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

z.show(df) 

enter image description here

+0

尼斯。由於沒有意識到這一點,我爲pyspark編寫了自己漂亮的打印函數(利用「%table」)。我無法在文檔中的任何地方找到它,但是... –

+1

@ TwUxTLi51Nus這是真的,這個部分的文檔不是很好。你可以找到關於ZeppelinContext [這裏](https://zeppelin.apache.org/docs/latest/interpreter/spark.html#zeppelincontext)和代碼([here](https://github.com)的一些信息/apache/zeppelin/blob/branch-0.7/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java))你可以看到所有可用的函數。另外,在筆記本中,您可以使用z變量上的ctrl +空格來檢查。 –

+0

ctrl +空格不適用於我,但是(在python中)''dir(z)''確實如此。 –