pyspark.sql.tvf.TableValuedFunction.range#

TableValuedFunction.range(start, end=None, step=1, numPartitions=None)[source]#

Create a DataFrame with single pyspark.sql.types.LongType column named id, containing elements in a range from start to end (exclusive) with step value step.

Added in version 4.0.0.

Parameters:
startint

the start value

endint, optional

the end value (exclusive)

stepint, optional

the incremental step (default: 1)

numPartitionsint, optional

the number of partitions of the DataFrame

Returns:
DataFrame

Examples

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

If only one argument is specified, it will be used as the end value.

>>> spark.tvf.range(3).show()
+---+
| id|
+---+
|  0|
|  1|
|  2|
+---+