range (SparkSession)

使用名为 的单个列创建一个,其中包含从<a0 />到(独占)的元素,其中包含步骤值

Syntax

range(start, end=None, step=1, numPartitions=None)

参数

参数 类型 Description
start int 起始值。
end int,可选 结束值(独占)。 如果省略, start 则用作结束值,范围从 0 开始。
step int,可选 增量步骤(默认值: 1) 。
numPartitions int,可选 的分区 DataFrame数。

退货

DataFrame

示例

spark.range(1, 7, 2).show()
# +---+
# | id|
# +---+
# |  1|
# |  3|
# |  5|
# +---+

# If only one argument is specified, it is used as the end value.
spark.range(3).show()
# +---+
# | id|
# +---+
# |  0|
# |  1|
# |  2|
# +---+