【发布时间】:2021-12-02 12:32:49
【问题描述】:
我正在尝试使用以下方法在 pyspark 数据框中加载 csv 文件:
spark.read.options(delimiter=';', header=True).csv(file)
但我收到以下错误
AnalysisException: 'Unable to infer schema for CSV. It must be specified manually.;'
我尝试手动插入架构,但它仍然没有加载任何值
customSchema = StructType([
StructField("aaa", StringType(), True),
StructField("bbb", IntegerType(), True),
StructField("ccc", IntegerType(), True)])
spark.read.option('header', 'true').option('delimiter', ';').schema(customSchema).csv(file)
spark.read.load(file, format="csv", header="true", sep=';', schema=customSchema)
我只得到一个带有列名的空数据框
【问题讨论】:
-
你能显示输入文件的示例行吗
-
你能展示一些示例输入吗?