Spark DataFrame 相当于 Pandas Dataframe `.iloc()` 方法? [英] Spark DataFrame equivalent to Pandas Dataframe `.iloc()` method?

查看:65
本文介绍了Spark DataFrame 相当于 Pandas Dataframe `.iloc()` 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用整数按位置引用 Spark DataFrame 列?

Is there a way to reference Spark DataFrame columns by position using an integer?

类似的 Pandas DataFrame 操作:

Analogous Pandas DataFrame operation:

df.iloc[:0] # Give me all the rows at column position 0 

推荐答案

不是真的,但你可以尝试这样的事情:

Not really, but you can try something like this:

Python:

df = sc.parallelize([(1, "foo", 2.0)]).toDF()
df.select(*df.columns[:1])  # I assume [:1] is what you really want
## DataFrame[_1: bigint]

df.select(df.columns[1:3])
## DataFrame[_2: string, _3: double]

斯卡拉

val df = sc.parallelize(Seq((1, "foo", 2.0))).toDF()
df.select(df.columns.slice(0, 1).map(col(_)): _*)

注意:

Spark SQL 不支持并且不太可能支持行索引,因此不可能跨行维度进行索引.

Spark SQL doesn't support and it is unlikely to ever support row indexing so it is not possible to index across row dimension.

这篇关于Spark DataFrame 相当于 Pandas Dataframe `.iloc()` 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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