代码之家  ›  专栏  ›  技术社区  ›  ZK Zhao

齐柏林飞艇:与弦混合时出现问题的表格显示

  •  0
  • ZK Zhao  · 技术社区  · 6 年前

    例如,如果我使用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

    我想知道,我怎么能把弦乐和齐柏林的桌子表演混在一起呢?

    我想这个问题可能是因为字符串导致齐柏林飞艇的表显示格式错误?

    1 回复  |  直到 6 年前
        1
  •  1
  •   zjffdu    6 年前

    嗯,这是齐柏林飞艇的问题。解决方法是添加'%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())