pyspark.sql.functions.left#

pyspark.sql.functions.left(str, len)[source]#

Returns the leftmost len`(`len can be string type) characters from the string str, if len is less or equal than 0 the result is an empty string.

New in version 3.5.0.

Parameters
strColumn or str

Input column or strings.

lenColumn or str

Input column or strings, the leftmost len.

Examples

>>> df = spark.createDataFrame([("Spark SQL", 3,)], ['a', 'b'])
>>> df.select(left(df.a, df.b).alias('r')).collect()
[Row(r='Spa')]