pyspark VectorUDT到整数或浮点的转换

pyspark VectorUDT到整数或浮点的转换,pyspark,apache-spark-sql,spark-dataframe,pyspark-sql,Pyspark,Apache Spark Sql,Spark Dataframe,Pyspark Sql,下面是我的数据框架 a、b、c、d 1 2 3 [1211] 2 2 4 [1222] 4 5 4 [12322] 这里的d列是向量类型,无法直接从vectorUDT转换为整数。下面是我的转换代码 newDF=newDF.selectcol'd', newDF.d.cast'int'。别名'd' 请有人提供帮助,我们可以使用udf重新序列化向量并访问值 >>>从pyspark.sql导入函数为F >>>从pyspark.sql.types导入IntegerType >>>df=spark.cre

下面是我的数据框架

a、b、c、d 1 2 3 [1211] 2 2 4 [1222] 4 5 4 [12322] 这里的d列是向量类型,无法直接从vectorUDT转换为整数。下面是我的转换代码

newDF=newDF.selectcol'd', newDF.d.cast'int'。别名'd'
请有人提供帮助,我们可以使用udf重新序列化向量并访问值

>>>从pyspark.sql导入函数为F >>>从pyspark.sql.types导入IntegerType >>>df=spark.createDataFrame[1,2,3,Vectors.dense[1211],2,2,4,Vectors.dense[1222],4,5,4,Vectors.dense[12322],[a','b','c','d'] >>>df.show +--+--+--+-----+ |a | b | c | d| +--+--+--+-----+ | 1| 2| 3| [1211.0]| | 2| 2| 4| [1222.0]| | 4| 5| 4|[12322.0]| +--+--+--+-----+ >>>打印模式 根 |-a:long nullable=true |-b:long nullable=true |-c:long nullable=true |-d:向量可为空=真 >>>udf1=F.udflambda x:intx[0],整数类型 >>>df.选择'd',udf1'd'。别名'd1'。显示 +-----+---+ |d | d1| +-----+---+ | [1211.0]| 1211| | [1222.0]| 1222| |[12322.0]|12322| +-----+---+ >>>df.选择'd',udf1'd'。别名'd1'。打印模式 根 |-d:向量可为空=真 |-d1:可为空的整数=真
预计的保存计数值是多少?