pyspark.sql.functions.floor#

pyspark.sql.functions.floor(col, scale=None)[source]#

Computes the floor of the given value.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

The target column or column name to compute the floor on.

scaleColumn or int, optional

An optional parameter to control the rounding behavior.

New in version 4.0.0.

Returns
Column

nearest integer that is less than or equal to given value.

Examples

Example 1: Compute the floor of a column value

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.floor(sf.lit(2.5))).show()
+----------+
|FLOOR(2.5)|
+----------+
|         2|
+----------+

Example 2: Compute the floor of a column value with a specified scale

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.floor(sf.lit(2.1267), sf.lit(2))).show()
+----------------+
|floor(2.1267, 2)|
+----------------+
|            2.12|
+----------------+