我在pyspark数据帧中有以下列,类型为Array[Int]。在
+--------------------+
| feature_indices|
+--------------------+
| [0]|
|[0, 1, 4, 10, 11,...|
| [0, 1, 2]|
| [1]|
| [0]|
+--------------------+
我试图用零填充数组,然后限制列表长度,这样每行数组的长度都是相同的。例如,对于n=5,我期望:
^{pr2}$有什么建议吗?我看过pysparkrpad
函数,但它只对字符串类型的列起作用。在
我最近在Keras中使用了
pad_sequences
函数来做类似的事情。我不确定你的用例,所以这可能是一个不必要的大依赖。在无论如何,这里是函数的文档链接:https://keras.io/preprocessing/sequence/#pad_sequences
输出:
^{pr2}$您可以编写一个
udf
来执行此操作:相关问题 更多 >
编程相关推荐