如何将Vector拆分为列 - 使用PySpark上下文:我有DataFrame2列:单词和向量。其中“vector”的列类型是VectorUDT。一个例子:word | vectorassert | [435,323,324,212...]我希望得到这个:word | v1 | v2 | v3 | v4 | v5 | v6 ......assert | 435 | 5435| 698| 356|....题:如何使用PySpark为每个维度拆分包含多列向量的列?提前致谢
2 回答

鸿蒙传说
TA贡献1865条经验 获得超7个赞
def splitVecotr(df, new_features=['f1','f2']):schema = df.schema cols = df.columnsfor col in new_features: # new_features should be the same length as vector column length schema = schema.add(col,DoubleType(),True)return spark.createDataFrame(df.rdd.map(lambda row: [row[i] for i in cols]+row.features.tolist()), schema)
该函数将特征向量列转换为单独的列
添加回答
举报
0/150
提交
取消