【问题标题】:Integertype() in schema StructType架构 StructType 中的 Integertype()
【发布时间】:2017-05-05 16:22:52
【问题描述】:

我正在尝试定义一个架构,以按照以下语法将空白列表转换为数据框:

data=[]

schema = StructType([
StructField("Table_Flag",StringType(),True),
StructField("TableID",IntegerType(),False),
StructField("Entry_No",StringType(),True),
StructField("Dimension_Code",StringType(),True),
StructField("Dimension_Value_Code",StringType(),True)
])

data=spark.createDataFrame(data,schema)

但它给出了名称“IntegerType”未定义的错误。 我尝试过使用 BooleanType、DecimalType、FloatType、IntegralType 但没有一个有效。只有 StringType 和 DataType 可用作数据类型。 根据文档 types.py IntegerType 在示例中定义。

请提出建议。我正在开发火花版本 2.0.1

【问题讨论】:

  • 你导入类型了吗? from pyspark.sql.types import *
  • 谢谢 Daniel.. 我刚刚导入了 StructType,StructField。

标签: apache-spark dataframe struct schema pyspark


【解决方案1】:

在文件开头添加import:

from pyspark.sql.types import IntegerType

甚至更简单:

from pyspark.sql.types import *

pyspark.sql.types导入所有类

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-02
    • 2015-07-24
    • 2017-09-22
    • 1970-01-01
    • 2016-07-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多