【问题标题】:Print out types of data frame columns in Spark在 Spark 中打印出数据框列的类型
【发布时间】:2016-09-24 01:13:06
【问题描述】:

我尝试在我的 Spark 数据帧上使用 VectorAssembler,但它抱怨它不支持 StringType 类型。我的数据框有 2126 列。

打印出所有列类型的编程方式是什么?

【问题讨论】:

    标签: pyspark


    【解决方案1】:

    df.printSchema() 将以易于遵循的格式打印数据框架构

    【讨论】:

    • AttributeError: 'DataFrame' object has no attribute 'printSchema'
    【解决方案2】:

    试试:

    >>> for name, dtype in df.dtypes:
    ...     print(name, dtype)
    

    >>> df.schema
    

    【讨论】:

    • AttributeError: 'DataFrame' object has no attribute 'schema'
    猜你喜欢
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 2022-09-27
    相关资源
    最近更新 更多