python - 将数组的数据类型从 double 更改为 int 的问题
问题描述
我有一组数据,我正在尝试编写一个 python 程序,该程序在将文件加载到数据块中时从模式级别更改数据类型。在将数组的数据类型从 DOUBLE 更改为 INT 时,我不断收到错误
架构
root
|-- _id: string (nullable = true)
|-- city: string (nullable = true)
|-- loc: array (nullable = true)
| |-- element: double (containsNull = true)
|-- pop: long (nullable = true)
|-- state: string (nullable = true)
我的代码
s= StructType([
StructField("_id",IntegerType(), True),
StructField("city",StringType(), True),
StructField("loc",ArrayType(), True),
StructField("element",DoubleType(), True),
StructField("pop",LongType(), True),
StructField("state",StringType(), True)
])
filepath= "/FileStore/tables/zips.json"
df2= spark.read.format("json").load(filepath, schema=s)
df2.show()
错误
TypeError: __init__() missing 1 required positional argument: 'elementType'
样本数据
解决方案
您错过了在ArrayType(elementType)中传递一个参数
错误:elementType 应该是 DataType
from pyspark.sql.types import *
ArrayType(IntegerType())
在此处查看更多信息:文档
推荐阅读
- sitecore - 是否可以更改 sitecore10.1 中的用户名验证?
- api - Shopware 6 Store-API 设置时事通讯收件人标签
- windows - Flutter windows 桌面应用程序兼容性
- java - 如何使用命令打开聚光灯
- woocommerce - 以编程方式更改 Woocommerce 订单状态
- python-3.x - 通过 plotly 创建大型 create_distplot 时内核滞后
- javascript - 运行标准超测示例
- java - 从 POJO 创建 JsonPath 的最佳方法
- c# - 命令未从我的视图模型触发 [XAMARIN FORMS]
- css - 关键帧动画CSS的特定悬停效果