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.

Added in version 3.5.0.

Parameters:
strColumn or str

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

lenColumn or str

Input column or strings, the leftmost len. A column that evaluates to an integer.

Examples

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