Skip to main content

rtrim

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

For the corresponding Databricks SQL function, see rtrim function.

Syntax​

Python
from pyspark.sql import functions as dbf

dbf.rtrim(col=<col>, trim=<trim>)

Parameters​

Parameter

Type

Description

col

pyspark.sql.Column or str

target column to work on.

trim

pyspark.sql.Column or str, optional

The trim string characters to trim, the default value is a single space. Added in Databricks Runtime 16.1

Parameter

Type

Description

col

pyspark.sql.Column or str

target column to work on.

trim

pyspark.sql.Column or str, optional

The trim string characters to trim, the default value is a single space. Added in Databricks Runtime 16.1

Returns​

pyspark.sql.Column: right trimmed values.

Examples​

Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([" Spark", "Spark ", " Spark"], "STRING")
df.select("*", dbf.rtrim("value")).show()
df = spark.createDataFrame(["***Spark", "Spark**", "*Spark"], "STRING")
df.select("*", dbf.rtrim("value", dbf.lit("*"))).show()
df = spark.createDataFrame([("**Spark*", "*"), ("==Spark=", "=")], ["value", "t"])
df.select("*", dbf.rtrim("value", "t")).show()