pyspark.sql.functions.pmod#

pyspark.sql.functions.pmod(dividend, divisor)[source]#

Returns the positive value of dividend mod divisor.

Added in version 3.4.0.

Parameters:
dividendColumn, column name or float

the column that contains dividend, or the specified dividend value. A column that evaluates to a numeric.

divisorColumn, column name or float

the column that contains divisor, or the specified divisor value. A column that evaluates to a numeric.

Returns:
Column

positive value of dividend mod divisor. Returns a column of the same type as the input.

Notes

Supports Spark Connect.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([
...     (1.0, float('nan')), (float('nan'), 2.0), (10.0, 3.0),
...     (float('nan'), float('nan')), (-3.0, 4.0), (-10.0, 3.0),
...     (-5.0, -6.0), (7.0, -8.0), (1.0, 2.0)],
...     ("a", "b"))
>>> df.select("*", sf.pmod("a", "b")).show()
+-----+----+----------+
|    a|   b|pmod(a, b)|
+-----+----+----------+
|  1.0| NaN|       NaN|
|  NaN| 2.0|       NaN|
| 10.0| 3.0|       1.0|
|  NaN| NaN|       NaN|
| -3.0| 4.0|       1.0|
|-10.0| 3.0|       2.0|
| -5.0|-6.0|      -5.0|
|  7.0|-8.0|       7.0|
|  1.0| 2.0|       1.0|
+-----+----+----------+