且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

打包列表以从 spark 数据框中选择多列

更新时间:2023-02-05 18:24:44

使用 df.select(cols.head, cols.tail: _*)

让我知道它是否有效:)

Let me know if it works :)

来自@的解释本:

key是select的方法签名:

The key is the method signature of select:

select(col: String, cols: String*)

cols:String* 条目采用可变数量的参数.:_* 解包参数,以便它们可以被这个参数处理.非常类似于在 python 中使用 *args 解包.请参阅此处此处 其他示例.

The cols:String* entry takes a variable number of arguments. :_* unpacks arguments so that they can be handled by this argument. Very similar to unpacking in python with *args. See here and here for other examples.