Skip to content

LazyColumn.str.cat

cat

cat(other: LazyColumn, sep: str = '') -> LazyColumn

Concatenates string columns element-wise with an optional separator.

Parameters:

Name Type Description Default
other LazyColumn

The string column to concatenate with.

required
sep str

The separator to place between the strings. Defaults to an empty string.

''

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn with concatenated strings. Null entries in either column result in null in the output.

Examples:

print(df.head())
#    first_name last_name
# 0     "John"    "Doe"
# 1     "Jane"    "Smith"
# 2     "Bob"     "Johnson"
# 3     None      "Brown"
# 4     "Alice"   None

# Concatenating first_name and last_name with a space separator
df["full_name"] = df["first_name"].str.cat(df["last_name"], sep=" ")
# Expected result:
# ["John Doe", "Jane Smith", "Bob Johnson", None, None]