pyspark.sql.functions.left(str: ColumnOrName, len: ColumnOrName) → pyspark.sql.column.Column[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.

strColumn or str

Input column or strings.

lenColumn or str

Input column or strings, the leftmost len.


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