gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 15:06:43 24 4
gpt4 key购买 nike

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


我试图通过以下方式使齐柏林飞艇的输出更好:

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!

最佳答案

在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

关于scala - 如何在Zeppelin/Spark/Scala中漂亮地打印数据框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com