pyspark.sql.functions.rtrim#

pyspark.sql.functions.rtrim(col)[source]#

Trim the spaces from right end for the specified string value.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to work on.

Returns
Column

right trimmed values.

Examples

>>> df = spark.createDataFrame(["   Spark", "Spark  ", " Spark"], "STRING")
>>> df.select(rtrim("value").alias("r")).withColumn("length", length("r")).show()
+--------+------+
|       r|length|
+--------+------+
|   Spark|     8|
|   Spark|     5|
|   Spark|     6|
+--------+------+