pyspark.sql.functions.btrim#

pyspark.sql.functions.btrim(str, trim=None)[source]#

Remove the leading and trailing trim characters from str.

Added in version 3.5.0.

Parameters:
strColumn or str

Input column or strings. A column that evaluates to a string.

trimColumn or str, optional

The trim string characters to trim, the default value is a single space. A column that evaluates to a string.

Examples

>>> df = spark.createDataFrame([("SSparkSQLS", "SL", )], ['a', 'b'])
>>> df.select(btrim(df.a, df.b).alias('r')).collect()
[Row(r='parkSQ')]
>>> df = spark.createDataFrame([("    SparkSQL   ",)], ['a'])
>>> df.select(btrim(df.a).alias('r')).collect()
[Row(r='SparkSQL')]