pyspark.sql.functions.factorial#
- pyspark.sql.functions.factorial(col)[source]#
Computes the factorial of the given value.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or str a column to calculate factorial for.
- col
- Returns
Column
factorial of given value.
Examples
>>> from pyspark.sql import functions as sf >>> spark.range(10).select("*", sf.factorial('id')).show() +---+-------------+ | id|factorial(id)| +---+-------------+ | 0| 1| | 1| 1| | 2| 2| | 3| 6| | 4| 24| | 5| 120| | 6| 720| | 7| 5040| | 8| 40320| | 9| 362880| +---+-------------+