Zeppelin:与字符串混合时有问题的表格显示

时间:2018-06-10 12:25:10

标签: pyspark apache-zeppelin

例如,如果我使用z.show()直接输出表

%pyspark
df = spark.createDataFrame([
    (0, 0, "2018-06-03", "2018-06-03"),
    (1, 1, "2018-06-04", "2018-06-04"),
    (2, 10, "2018-06-03", None),
    (4, 1, "2018-06-05", "2018-06-01")])\
  .toDF("orderid", "customerid", "product_name", "product_name2")
print("test print string 1")
z.show(df)
z.show(df.describe())

输出很好,就像这个

enter image description here

但是,如果我在输出表之间添加一个字符串

%pyspark
df = spark.createDataFrame([
    (0, 0, "2018-06-03", "2018-06-03"),
    (1, 1, "2018-06-04", "2018-06-04"),
    (2, 10, "2018-06-03", None),
    (4, 1, "2018-06-05", "2018-06-01")])\
  .toDF("orderid", "customerid", "product_name", "product_name2")
print("test print string 1")
z.show(df)
print("test print string 2") # If I add this
z.show(df.describe())

输出变为此,(没有显示表格)

enter image description here

我想知道,我怎样才能将弦乐和Zeppelin的表格混合在一起?

我认为问题可能是由于字符串导致Zeppelin的表显示格式错误?

1 个答案:

答案 0 :(得分:1)

嗯,这是齐柏林飞艇的问题。解决方法是添加'%text'以明确指定输出类型,如下所示

df = spark.createDataFrame([
    (0, 0, "2018-06-03", "2018-06-03"),
    (1, 1, "2018-06-04", "2018-06-04"),
    (2, 10, "2018-06-03", None),
    (4, 1, "2018-06-05", "2018-06-01")])\
  .toDF("orderid", "customerid", "product_name", "product_name2")
print("test print string 1")
z.show(df)
print("%text test print string 2") # If I add this
z.show(df.describe())