range (SparkSession)
Creates a DataFrame with a single LongType column named id, containing elements in a range from start to end (exclusive) with step value step.
Syntax
range(start, end=None, step=1, numPartitions=None)
Parameters
Parameter | Type | Description |
|---|---|---|
| int | The start value. |
| int, optional | The end value (exclusive). If omitted, |
| int, optional | The incremental step (default: |
| int, optional | The number of partitions of the |
Returns
DataFrame
Examples
Python
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|
# +---+