Upacking列表以选择火花数据帧多列 [英] Upacking a list to select multiple columns from a spark data frame

查看:149
本文介绍了Upacking列表以选择火花数据帧多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个火花数据帧东风。有子的使用这些列的列表中选择一个几列的方式?

I have a spark data frame df. Is there a way of sub selecting a few columns using a list of these columns?

斯卡拉> df.columns
RES0:数组[字符串] =阵列(A,B,C,D)

我知道我可以这样做 df.select(B,C)。但是假设我有一个包含一些列名的列表 VAL COLS =名单(B,C),有没有办法通过这df.select? df.select(COLS)抛出一个错误。喜欢的东西df.select(* COLS),如蟒蛇

I know I can do something like df.select("b", "c"). But suppose I have a list containing a few column names val cols = List("b", "c"), is there a way to pass this to df.select? df.select(cols) throws an error. Something like df.select(*cols) as in python

推荐答案

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

让我知道,如果它的工作原理:)

Let me know if it works :)

这篇关于Upacking列表以选择火花数据帧多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆