pyspark.sql.Column.substr

Column.substr(startPos: Union[int, Column], length: Union[int, Column]) → pyspark.sql.column.Column

Return a Column which is a substring of the column.

Parameters
startPosColumn or int

start position

lengthColumn or int

length of the substring

Examples

>>> df.select(df.name.substr(1, 3).alias("col")).collect()
[Row(col='Ali'), Row(col='Bob')]