如何在csv文件中传递structtype

2024-05-16 04:08:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有大约300个变量,我正试图通过csv传递customschema。 下面是我正在使用的示例代码。 但是,在通过csv文件上载架构时…输出不包含列列表:

Output : StructType(List(StructField(StructType([,StringType,true)))

CSV格式的代码:

schema = StructType([ \
            StructField("COl1",StringType(),True), \
            StructField("COL2",DecimalType(20,10),True), \
            StructField("COL3",DecimalType(20,10),True)
        ])

# reading schema
sch_df = spark.read.option("header", "true").csv("schema.csv").schema
# Passing schema
df = spark.read.schema(sch_df).option("header", "true").csv("/sample.csv")

您能否立即提供通过csv文件上传模式的权限


Tags: 文件csv代码truedfreadschemaspark