factorial
Computes the factorial of the given value. Supports Spark Connect.
For the corresponding Databricks SQL function, see factorial function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.factorial(col=<col>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| a column to calculate factorial for. |
Returns
pyspark.sql.Column: factorial of given value.
Examples
Python
from pyspark.databricks.sql import functions as dbf
spark.range(10).select("*", dbf.factorial('id')).show()
Output
+---+-------------+
| id|factorial(id)|
+---+-------------+
| 0| 1|
| 1| 1|
| 2| 2|
| 3| 6|
| 4| 24|
| 5| 120|
| 6| 720|
| 7| 5040|
| 8| 40320|
| 9| 362880|
+---+-------------+