pyspark.sql.functions.btrim

pyspark.sql.functions.btrim(str: ColumnOrName, trim: Optional[ColumnOrName] = None) → pyspark.sql.column.Column[source]

Remove the leading and trailing trim characters from str.

New in version 3.5.0.

Parameters
strColumn or str

Input column or strings.

trimColumn or str

The trim string characters to trim, the default value is a single space

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')]