Skip to content

LazyColumn.str.slice

slice

slice(
    start: Optional[int] = None, stop: Optional[int] = None
) -> LazyColumn

Slices substrings from each string in the column.

Parameters:

Name Type Description Default
start int

The start position for the slice. If None, defaults to 0.

None
stop int

The end position for the slice. If None, slices to the end of the string.

None

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn with sliced strings.

Examples:

print(df.head())
#    col1 my_string_column
# 0     1         "Hello"
# 1     2         "World"
# 2     3         "Test123"
# 3     4         None
# 4     5         "abc"

df["my_string_column"].str.slice(1, 3)
# ["el", "or", "es", None, "bc"]